Date and time functions in SQL server are scalar functions that perform an operation on a date and time input value and returns either a string, numeric, or date and time value.
All functions are listed below:
Function
Description
CURRENT_TIMESTAMP
Returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is not included.
Syntax:
CURRENT_TIMESTAMP
Function
Description
DATEADD
Returns a new datetime value based on adding an interval to the specified date.
Syntax:
DATEADD (datepart , number, date )
Function
Description
DATEDIFF
Returns the number of date and time boundaries crossed between two specified dates.
TODATETIMEOFFSET transforms a datetime2 value into a datetimeoffset value. The datetime2 value is interpreted in local time for the specified time_zone.
Returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is not included.
Syntax:
SYSDATETIME ( )
Function
Description
SYSDATETIMEOFFSET
Returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is included.
Syntax:
SYSDATETIMEOFFSET ( )
Function
Description
SYSUTCDATETIME
Returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The date and time is returned as UTC time (Coordinated Universal Time).