getdate () function
Returns the current date and time of the system in the default format of datetime
Syntax format: getdate ()
Year () Month () Day () function
Returns the year, month, and date value in Date_expression
Syntax format: year/month/day (date_expression datetime/varchar) Returns int
Example: Year (GETDATE ()), year (' 2016-05-01 ')
datename () function
Returns the specified part of a date as a string
Syntax format: datename (datepart,date_expression)
Example: Datename (Month,getdate ()), Datename (year, ' 2016-05-01 ')
datepart () function
Returns the specified part of a date as an integral type
Syntax format: DATEPART (datepart,date_expression)
DateAdd () function
Returns the new date specified by date plus the specified extra date interval number
Syntax format: DATEADD (datepart,number,date)
Cases:
Add 2 months on the specified date
DATEADD (mm,2, ' 2016-05-11 ') 2016-07-11
DATEADD (Mm,2,getdate ())
Minus 2 months on a specified date
DATEADD (mm,-2, ' 2016-05-11 ')
DATEADD (Mm,-2,getdate ())
DateDiff () function
Returns the datepart difference between the specified two dates, that is, the gap value of StartDate and EndDate, and the result is a signed integer value
Syntax format: DateDiff (Datepart,startpart,endpart)
Example: DATEDIFF (DD, ' 2016-05-01 ', ' 2016-07-10 ') returns 70, the number of days gap value is 70
DATEDIFF (MM, ' 2016-05-01 ', ' 2016-07-10 ') returns 2, month gap value is 2
SQL Time Date function