Datetime Functions in SQL Server and Datepart Abbreviations
You can use the datetime functions in SQL Server to manipulate the datetime values. You can either use arithmetic operations on datetime or parse datetime values. The following list contains the datetimefunctions in SQL Server with examples
| Function Name | Parameters | Description | Example | O/P |
| Dateadd | (datepart,Number,Date) | Adds the number of dateparts to the date | Select dateadd(yy,2,’01/25/2000′) | 1/25/2002 |
| datediff | (datepart, date1, date2) | Calculates the number of dateparts between two dates | Select Datediff(d,’01/25/2000′,’01/30/2000′) | 5 |
| DateName | (datepart, date) | Returns the datepart from the listed date ( ex: december) | Select DATENAME(Month,’01/25/2000′) | January |
| Getdate | () | Returns current date time | Select Getdate() | |
| day | (date) | Returns an integer , represents the day | Select Day(’01/25/2000′) | 25 |
| Getutcdate | () | Returns the current date from the system in Universal time coordinate(UTC) time | Select Getutcdate() | |
| Month | (date) | Retuns the month as integer | Select Month(’01/25/2000′) | 1 |
| Year | (date) | Returns an integer , representing the year | Select Year(’01/25/2000′) | 2000 |
SQL server provides the following list of abbreviations for datepart functions