Menu

SQL Server Date and Time Functions

Choose a SQL Server date/time function by task:

  • Get the current date only: CURRENT_DATE on SQL Server 2025+ and supported Azure SQL/Fabric services; on SQL Server 2022 and earlier, use CONVERT(date, GETDATE()).
  • Get the current system time: GETDATE() (also available as CURRENT_TIMESTAMP), SYSDATETIME() for higher fractional precision, GETUTCDATE() or SYSUTCDATETIME() for UTC, or SYSDATETIMEOFFSET() when you need the current system offset.
  • Add an interval, get a month end, or compare dates: DATEADD(), EOMONTH(), DATEDIFF(), and DATEDIFF_BIG() (SQL Server 2016+) for a bigint boundary 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, or YEAR(), MONTH(), and DAY().
  • Extract an hour, minute, or second: use DATEPART(hour|minute|second, value) in native T-SQL. SQL Server also accepts the ODBC escape functions HOUR(), MINUTE(), and SECOND() as {fn ...} expressions; they are not bare T-SQL function calls.
  • Work with time zones: use AT TIME ZONE for named zones and daylight-saving rules, TODATETIMEOFFSET() to attach a known offset to local time, or SWITCHOFFSET() to display an existing datetimeoffset with another offset while preserving its UTC instant.

The complete reference for each function follows below.

  1. AT TIME ZONE

    Convert SQL Server date/time values using named time zones, UTC offsets, and daylight-saving rules with AT TIME ZONE.
  2. 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.
  3. DATE_BUCKET

    Use SQL Server 2022 DATE_BUCKET() to group date/time values into fixed-width intervals and align buckets with an origin.
  4. DATEADD

    Use SQL Server DATEADD() for date arithmetic, including month-end behavior and SQL Server 2025 bigint intervals.
  5. DATEDIFF

    Learn how SQL Server DATEDIFF() counts date-part boundaries, with examples, supported parts, limits, and when to use DATEDIFF_BIG().
  6. DATEDIFF_BIG

    Use SQL Server DATEDIFF_BIG() to count date-part boundaries as a bigint when DATEDIFF() may overflow.
  7. 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.
  8. DATEPART

    Use SQL Server DATEPART() to extract a numeric year, month, day, hour, minute, or other supported part from a date or time value.
  9. DATETRUNC

    Use SQL Server 2022 DATETRUNC() to truncate dates to a year, month, week, day, or supported time part.
  10. DAY

    In SQL Server, the DAY() function is used to extract the day of the month from a date expression.
  11. EOMONTH

    Use SQL Server EOMONTH() to return the last date of a month, optionally offset by a number of months.
  12. GETDATE

    Return the current SQL Server system date and time as datetime, without a time-zone offset; CURRENT_TIMESTAMP is its ANSI synonym.
  13. GETUTCDATE

    Return the current UTC date and time as datetime without a time-zone offset; use SYSUTCDATETIME() for higher precision.
  14. MONTH

    MONTH() is a date-time function in SQL Server used to return the month part of a given date.
  15. ODBC HOUR

    Use the SQL Server ODBC HOUR scalar function as {fn HOUR(...)}; for native T-SQL, use DATEPART(hour, …).
  16. ODBC MINUTE

    Use the SQL Server ODBC MINUTE scalar function as {fn MINUTE(...)}; for native T-SQL, use DATEPART(minute, …).
  17. ODBC SECOND

    Use the SQL Server ODBC SECOND scalar function as {fn SECOND(...)}; for native T-SQL, use DATEPART(second, …).
  18. SWITCHOFFSET

    Use SQL Server SWITCHOFFSET() to display a datetimeoffset value with a different numeric offset while preserving its UTC instant.
  19. SYSDATETIME

    Return the current system date and time as datetime2(7) with 100-nanosecond precision and no time-zone offset.
  20. SYSDATETIMEOFFSET

    Return the current system date and time as datetimeoffset(7), including the system’s current UTC offset.
  21. SYSUTCDATETIME

    Return the current UTC date and time as datetime2(7); the result has no time-zone offset.
  22. 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.
  23. YEAR

    The YEAR() function is one of the date and time functions in SQL Server, used to extract the year from a given date/time value.