sql special dates

. --a first day of the month 
select dateadd (mm, datediff (mm , 0, getdate ()), 0) as the first day of the month 

--b the last day of this month. 
the SELECT DATEADD (MS, - 3, dateadd (mm, datediff ( mm, 0, getdate ()) + 1, 0)) as of the last day of this month 

--c. last month, the last day of the 
select dateadd (ms, -3, dateadd (mm, datediff (mm, 0, getdate ( )), 0)) as of the last day of last month 

--d. this week's Monday 
select dateadd (wk, datediff (wk , 0, getdate ()), 0) as this week of Monday 

--e. the first day of the quarter, 
select dateadd (qq, datediff (qq , 0, getdate ()), 0) as the first day of the quarter 

--f. the last day of the quarter 
select dateadd (ms, -3, dateadd (qq , datediff (qq, 0, getdate ()) + 1, 0)) as of the last day of the quarter 

--g. the first Monday of the month 
select dateadd (wk, datediff (wk, 0, dateadd (dd , 6-datepart (day, getdate ()), getdate ())), 0) as the first Monday of the month 

--h. the first day of the year
select dateadd (yy, datediff (yy , 0, getdate ()), 0) as the first day of the year 

--i. the last day of the year 
select dateadd (ms, -3, dateadd (yy, datediff (yy, 0, getdate ()) + 1 , 0)) as of the last day of the year 

--j. last year, the last day of the 
select dateadd (ms, -3, dateadd (yy, datediff (yy, 0, getdate ()), 0 )) as of the last day of last year

  

Guess you like

Origin www.cnblogs.com/lgx5/p/11614067.html