The date and time of the date function cardinality expression or the return value from the time interval.
GETDATE (), returns the date and time of the current system. Cases:
SELECT GETDATE (); The result: 2010-05-18 15:53:08.920
DATEPART (Item,date), returns the date specified by the item (Year,month,day,,weekday,hour,minute,secound, etc.), or the corresponding shorthand (year:y), returning the result to an integer. Cases:
SELECT DATEPART (year, ' 2010-05-18 '); The result is: 2010
SELECT DATEPART (MONTH, ' 2010-05-18 '); The result is: 5
SELECT DATEPART (Day, ' 2010-05-18 '); The result is: 18
SELECT DATEPART WEEKDAY, ' 2010-05-18 '); Results: 3 (Tuesday)
SELECT DATEPART (HOUR, ' 2010-05-18 15:59:30 '); The result is: 15
SELECT DATEPART (MINUTE, ' 2010-05-18 15:59:30 '); The result is: 59
SELECT DATEPART (SECOND, ' 2010-05-18 15:59:30 '); The result is: 30
Datename (Item,date), returns the specified item,date of the date as a string. Cases:
SELECT datename (WEEKDAY, ' 2010-05-18 '); Results were: Tuesday
DATEDIFF (ITEM,DATE1,DATE2), calculates the difference between two date parts date1 and Date2, and returns the result of item representing the integer value of the cell. Cases:
SELECT DATEDIFF (year, ' 2000-1-1 ', ' 2010-05-18 '); Result is 10
SELECT DATEDIFF (year, ' 2010-05-18 ', ' 2000-1-1 '); Result is-10
SELECT DATEDIFF (MONTH, ' 2010-01-01 ', ' 2010-05-18 '); Result is 4
SELECT DATEDIFF (Day, ' 2010-05-01 ', ' 2010-05-18 '); Result is 17
DATEADD (i,n,d), the number n in the I-value unit is increased to the specified date d. The result is a datetime type. Cases:
SELECT DATEADD (day,7, ' 2010-05-18 '); The result: 2010-05-25 00:00:00.000
SELECT DATEADD (year,-5, ' 2010-05-18 '); The result: 2005-05-18 00:00:00.000
T_sql Date function