当前月日期

/************************************** 从1月1号开始排  ************************************** / 
 
 
declare @date datetime,@startDate varchar(10)
set @date='2013-11-1'
set @startDate=convert(varchar(8),@date,120)+'01'
select convert(varchar(10),dateadd(dd,number,@startDate),120) as dateOnly,
convert(varchar(10),dateadd(dd,number,@startDate),120)+'<br/>'+datename(weekday,convert(varchar(10),dateadd(dd,number,@startDate),120))  as dateWeek
from master..spt_values 
where type='P' 
and dateadd(dd,number,@startDate)<=dateadd(dd,-1,convert(varchar(8),dateadd(mm,1,@date),120)+'01')

 

 
/**************************************  从星期天开始排  ************************************** / 
 
 
declare @date datetime,@startDate varchar(10)
set @date='2013-11-1'
set @startDate=convert(varchar(10),dateadd(dd,-datepart(dw,@date)+1,@date),120)
select convert(varchar(10),dateadd(dd,number,@startDate),120) as dateOnly,
convert(varchar(10),dateadd(dd,number,@startDate),120)+'<br/>'+datename(weekday,convert(varchar(10),dateadd(dd,number,@startDate),120))  as dateWeek
from master..spt_values 
where type='P' 
and dateadd(dd,number,@startDate)<=dateadd(dd,-1,convert(varchar(8),dateadd(mm,1,@date),120)+'01')

 

 
 
/*****************************************************************************************************/
            //一个月总天数
                    int rowsCount=dsStaffVisitsPlanM.Tables[0].Rows.Count;  
                    if (rowsCount > 0)
                    {
                        
                        //一个月总星期数
                        for (int wCount = 1; wCount <= (rowsCount % 7 == 0 ? rowsCount / 7 : rowsCount / 7 + 1); wCount++)
                        {
                            //标题
                            sbM.Append("<tr class='bgEFEFEF'>");
                            sbM.Append("<td></td>");
                            for (int daycount = 1; daycount <= 7; daycount++)
                            {
                                int index=(wCount-1) * 7 +(daycount-1);  //日期的下标
                                if (index < rowsCount)
                                {
                                    sbM.Append("<td>" + dsStaffVisitsPlanM.Tables[0].Rows[index]["dateOnly"].ToString() + "</td>");
                                }
                                else
                                {
                                    sbM.Append("<td></td>");
                                }
 
                                if (daycount % 7 == 0)
                                {
                                    sbM.Append("</tr>");
                                }
                            }
                        } 
                    }

 

                   
posted @ 2014-08-18 10:06  linyongqin  阅读(115)  评论(0编辑  收藏  举报