--- The first day of a month
Select dateadd (mm, DATEDIFF (mm, 0, getdate (), 0)
--- Monday of this week
Select dateadd (wk, DATEDIFF (wk, 0, getdate (), 0)
--- The first day of a year
Select dateadd (yy, DATEDIFF (yy, 0, getdate (), 0)
---- The first day of the quarter
Select dateadd (qq, DATEDIFF (qq, 0, getdate (), 0)
---- Last day of last month
SELECT dateadd (MS,-3, DATEADD (mm, DATEDIFF (mm, 0, getdate (), 0 ))
---- Last day of last year
SELECT dateadd (MS,-3, DATEADD (yy, DATEDIFF (yy, 0, getdate (), 0 ))
---- The last day of this month
SELECT dateadd (MS,-3, DATEADD (mm, DATEDIFF (m, 0, getdate () + 1, 0 ))
----- The first Monday of this month
Select DATEADD (wk, DATEDIFF (wk, 0,
Dateadd (DD, 6-datepart (day, getdate (), getdate ())
), 0)
--- The last day of this year
Select dateadd (MS,-3, dateadd (YY, datediff (YY, 0, getdate () + 1, 0 )).
---- Conversion time format
Select convert (varchar (30), getdate (), 101) now
101/DD/yy
102 YY-mm-dd
103 dd/mm/yy
104 DD-mm-yy
105 DD-mm-yy
106 dd mon YY
107 mon DD, YY
108 hh: mm: SS
9 or 109 mon dd yyyy hh: MI: SS: mmmmam (or pm)
110-dd-yy
111 YY/MM/dd
112 yymmdd
13 or 113 dd mon yyyy hh: MI: SS: Mmm (in 24-hour format)
114 hh: MI: SS: Mmm (in 24-hour format)
20 or 120 | yyyy-mm-dd hh: MI: SS (in 24-hour format)
21 or 121 | yyyy-mm-dd hh: MI: SS: Mmm (in 24-hour format)