* The datepart () function allows you to conveniently retrieve all parts of the period.
* Date: 18:15:36. 513
* YY: 2006 of the year
* Mm: 7 months
* DD: 2 days in the month
* DY: 183 days in the year
* WK: week 27 in the year
* DW: The day in the week.
* QQ: Quarter 3 of the year
* Hh: 18 hours
* Mi: 15 minutes
* Ss: 36 seconds
* The following simple statements demonstrate the obtained results:
*/
Select getdate ()
Select datepart (mm, getdate ())
Select datepart (YY, getdate ())
Select datepart (DD, getdate ())
Select datepart (dy, getdate ())
Select datepart (wk, getdate ())
Select datepart (DW, getdate ())
Select datepart (QQ, getdate ())
Select datepart (HH, getdate ())
Select datepart (MI, getdate ())
Select datepart (SS, getdate ())
Select datediff (DD, getdate (), '2014/1/123') -- calculates the number of days from today
Select datediff (mm, getdate (), '2014/1/123') -- calculates the number of months from today till.
Select datename (mm, getdate () -- Obtain the month of today in the form of a string instead of a number (07)
Select dateadd (DD, 30, getdate () -- add 30 days to the current date
Select dateadd (mm, 3, getdate () -- add 3 months to the current date
Select dateadd (YY, 1, getdate () -- add one year to the current date
Select dateadd (QQ, datediff (QQ, 0, getdate (), 0) -- get the first day of this quarter
Select dateadd (mm,-3, dateadd (QQ, datediff (QQ, 0, getdate (), 0) -- get the first day of the previous master and quarter