Using AT TIME ZONE

The AT TIME ZONE expression can be used to represent time in a given time zone. It converts an input date to the corresponding datetimeoffset value in the target time zone. It has the following two arguments:

  • inputdate: This is an expression of the following date data types: smalldatetime, datetime, datetime2, and datetimeoffset.
  • timezone: This is the name of the target time zone. The allowed zone names are listed in the sys.time_zone_info catalog view.

The return type of the expression is datetimeoffset in the target time zone.

Use the following code to display local UTC time, and the local time in New York and Vienna:

SELECT CONVERT(DATETIME, SYSDATETIMEOFFSET()) AS UTCTime, CONVERT(DATETIME, SYSDATETIMEOFFSET() AT ...

Get SQL Server 2017 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.