SQL Server Date and Time Functions
This page lists the commonly used date and time functions in SQL Server.
-
DATEADD
TheDATEADD()
function is a function in SQL Server used to add or subtract a specified time interval from a date. -
DATEDIFF
TheDATEDIFF()
function in SQL Server is used to calculate the time difference between two dates, and can return results in units such as years, months, days, hours, minutes, and seconds. -
DATENAME
The SQL ServerDATENAME()
function is used to return the name of a specified part of a date value. -
DATEPART
TheDATENAME()
function is a date and time function in Microsoft SQL Server used to extract a specific part of a date or time, such as the year, month, hour, or minute. -
DAY
In SQL Server, theDAY()
function is used to extract the day of the month from a date expression. -
GETDATE
In SQL Server, theGETDATE()
function is used to return the current system date and time. -
HOUR
In SQL Server, theHOUR()
function is used to retrieve the hour part of a given time value. -
MINUTE
In SQL Server, theMINUTE()
function is used to extract the minute part of a time value. -
MONTH
MONTH()
is a date-time function in SQL Server used to return the month part of a given date. -
SECOND
SECOND()
is a built-in SQL Server function used to extract the seconds (0-59) part from a datetime value. -
SWITCHOFFSET
TheSWITCHOFFSET()
function in SQL Server is used to change the time zone offset of a datetime value and returns the new datetime. -
SYSDATETIME
TheSYSDATETIME()
function in SQL Server returns the current system date and time. -
SYSDATETIMEOFFSET
In SQL Server, theSYSDATETIMEOFFSET()
function returns the current system date and time along with the time zone offset from Coordinated Universal Time (UTC). -
SYSUTCDATETIME
TheSYSUTCDATETIME()
function in SQL Server is used to return the current system UTC date and time value. -
TODATETIMEOFFSET
InSQL Server, theTODATETIMEOFFSET()
function allows combining a datetime value with a time zone offset value to create aDateTimeOffset
value. -
YEAR
TheYEAR()
function is one of the date and time functions in SQL Server, used to extract the year from a given date/time value.