巧妙的Sql函数日期处理方法
/*本月第一天日期*/
SELECT FirstDayOfCurrentMonth = dateadd(mm,datediff(mm,0,getdate()),0)
SELECT FirstDayOfCurrentMonth = convert(CHAR(8),getdate(),120)+'1'
/*下月第一天日期*/
SELECT FirstDayOfNextMonth = dateadd(mm,datediff(mm,0,getdate())+1,0)
/*本月最后一天日期*/
SELECT LastDayOfCurrentMonth = dateadd(dd,-1,dateadd(mm,datediff(mm,0,getdate())+1,0))
SELECT LastDayOfCurrentMonth = dateadd(dd,-1,convert(DATETIME,convert(CHAR(8),dateadd(mm,1,getdate()),120)+'1'))
/*本月天数*/
SELECT NumberOfDaysOfCurrentMonth =
convert(INT,
dateadd(mm,datediff(mm,0,getdate())+1,0)
-
dateadd(mm,datediff(mm,0,getdate()),0))
SELECT NumberOfDaysOfCurrentMonth = day(dateadd(day,-1,convert(CHAR(8),dateadd(month,1,getdate()),120)+'1'))