About SQL Server database date functions
1. Get current time Select GETDATE ()
2, intercept the required value
Select DATEPART (year,getdate ())
Select DATEPART (month,getdate ())
Select DATEPART (day,getdate ())
Select DATEPART (hour,getdate ())
Select DATEPART (minute,getdate ())
Select DATEPART (second,getdate ())
Select DATEPART (week,getdate ())
3. Add or subtract a specified time interval from a date
Select DATEADD (Year,3,getdate ())--Get the current time and defer three years in the future
Select DATEADD (Month,3,getdate ())--Get the current time and defer three months later
Select DATEADD (Day,3,getdate ())--Get the current time and defer three days in the future
Select DATEADD (Hour,3,getdate ())--Get the current time and defer three hours later
Select DATEADD (Minute,3,getdate ())--Get the current time and defer three minutes later
Select DATEADD (Second,3,getdate ())--Get the current time and defer three seconds later
4. Returns the time between two dates
Select DateDiff (year, ' 2001-08-19 ', GETDATE ())--2001-08-19 and current time difference between the young
Number of months between select DateDiff (month, ' 2001-08-19 ', GETDATE ())--2001-08-19 and current time
Select DateDiff (Day, ' 2001-08-19 ', GETDATE ()) How many days difference between--2001-08-19 and current time
5. Display date/time in different format
Select CONVERT (Char,getdate (), 8)--show current time-minute-second
Select CONVERT (Char,getdate (), 10)--show current month-day-year, display form "08-19-11"
Select CONVERT (Char,getdate (), 11)--show current year-month-day, display form "11/08/19"
Select CONVERT (Char,getdate (), 14)--show current time-minutes-seconds-milliseconds, display form "14:54:57:090"
Note: Parameter 1-14 is optional.
About SQL Server database date functions