SQL Server Date and Time Functions
Choose a SQL Server date/time function by task:
- Get the current date only:
CURRENT_DATEon SQL Server 2025+ and supported Azure SQL/Fabric services; on SQL Server 2022 and earlier, useCONVERT(date, GETDATE()). - Get the current system time:
GETDATE()(also available asCURRENT_TIMESTAMP),SYSDATETIME()for higher fractional precision,GETUTCDATE()orSYSUTCDATETIME()for UTC, orSYSDATETIMEOFFSET()when you need the current system offset. - Add an interval, get a month end, or compare dates:
DATEADD(),EOMONTH(),DATEDIFF(), andDATEDIFF_BIG()(SQL Server 2016+) for abigintboundary count. - Group values into fixed-width date/time intervals:
DATE_BUCKET()(SQL Server 2022 and later). - Truncate a value to the start of a date part:
DATETRUNC()(SQL Server 2022 and later). - Extract a date or time part in T-SQL: use
DATEPART()for a numeric value,DATENAME()for a name, orYEAR(),MONTH(), andDAY(). - Extract an hour, minute, or second: use
DATEPART(hour|minute|second, value)in native T-SQL. SQL Server also accepts the ODBC escape functionsHOUR(),MINUTE(), andSECOND()as{fn ...}expressions; they are not bare T-SQL function calls. - Work with time zones: use
AT TIME ZONEfor named zones and daylight-saving rules,TODATETIMEOFFSET()to attach a known offset to local time, orSWITCHOFFSET()to display an existingdatetimeoffsetwith another offset while preserving its UTC instant.
The complete reference for each function follows below.
-
AT TIME ZONE
Convert SQL Server date/time values using named time zones, UTC offsets, and daylight-saving rules with AT TIME ZONE. -
CURRENT_DATE
Use CURRENT_DATE on SQL Server 2025+ and supported Azure SQL/Fabric services; use CONVERT(date, GETDATE()) on SQL Server 2022 and earlier. -
DATE_BUCKET
Use SQL Server 2022 DATE_BUCKET() to group date/time values into fixed-width intervals and align buckets with an origin. -
DATEADD
Use SQL Server DATEADD() for date arithmetic, including month-end behavior and SQL Server 2025 bigint intervals. -
DATEDIFF
Learn how SQL Server DATEDIFF() counts date-part boundaries, with examples, supported parts, limits, and when to use DATEDIFF_BIG(). -
DATEDIFF_BIG
Use SQL Server DATEDIFF_BIG() to count date-part boundaries as a bigint when DATEDIFF() may overflow. -
DATENAME
Use SQL Server DATENAME() to return a date-part string such as a month name or weekday; see supported parts, language behavior, and examples. -
DATEPART
Use SQL Server DATEPART() to extract a numeric year, month, day, hour, minute, or other supported part from a date or time value. -
DATETRUNC
Use SQL Server 2022 DATETRUNC() to truncate dates to a year, month, week, day, or supported time part. -
DAY
In SQL Server, theDAY()function is used to extract the day of the month from a date expression. -
EOMONTH
Use SQL Server EOMONTH() to return the last date of a month, optionally offset by a number of months. -
GETDATE
Return the current SQL Server system date and time asdatetime, without a time-zone offset;CURRENT_TIMESTAMPis its ANSI synonym. -
GETUTCDATE
Return the current UTC date and time as datetime without a time-zone offset; use SYSUTCDATETIME() for higher precision. -
MONTH
MONTH()is a date-time function in SQL Server used to return the month part of a given date. -
ODBC HOUR
Use the SQL Server ODBC HOUR scalar function as{fn HOUR(...)}; for native T-SQL, use DATEPART(hour, …). -
ODBC MINUTE
Use the SQL Server ODBC MINUTE scalar function as{fn MINUTE(...)}; for native T-SQL, use DATEPART(minute, …). -
ODBC SECOND
Use the SQL Server ODBC SECOND scalar function as{fn SECOND(...)}; for native T-SQL, use DATEPART(second, …). -
SWITCHOFFSET
Use SQL Server SWITCHOFFSET() to display a datetimeoffset value with a different numeric offset while preserving its UTC instant. -
SYSDATETIME
Return the current system date and time as datetime2(7) with 100-nanosecond precision and no time-zone offset. -
SYSDATETIMEOFFSET
Return the current system date and time as datetimeoffset(7), including the system’s current UTC offset. -
SYSUTCDATETIME
Return the current UTC date and time as datetime2(7); the result has no time-zone offset. -
TODATETIMEOFFSET
Use SQL Server TODATETIMEOFFSET() to attach a known numeric UTC offset to a local date/time value; learn when to use AT TIME ZONE instead. -
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.