Get the Current Time Zone of the Server in SQL Server (T-SQL)

Microsoft introduced the CURRENT_TIMEZONE() function in SQL Server 2019 for returning the time zone of the server.

More specifically, this function “returns the name of the time zone observed by a server or an instance”.

Example

Here’s an example to demonstrate.

SELECT CURRENT_TIMEZONE();

Result:

(UTC) Coordinated Universal Time

In this case, the time zone of my instance of SQL Server is UTC.

I can see this when I run functions like SYSDATETIMEOFFSET().

SELECT SYSDATETIMEOFFSET();

Result:

2020-04-01 00:14:44.0470785 +00:00

UTC has a time zone offset of +00:00 (no offset), and this is reflected when I return the system’s date and time.

Earlier Versions of SQL Server

If I run CURRENT_TIMEZONE() against my SQL Server 2017 instance, here’s what I get.

SELECT CURRENT_TIMEZONE();

Result:

Msg 195, Level 15, State 10, Line 1
'CURRENT_TIMEZONE' is not a recognized built-in function name.

I even downloaded the latest Docker container with SQL Server 2017 for Linux to check this, but I still get this error.

I’ve also checked other SQL Server 2017 installations but with the same result.

In the comments section of its online documentation for this function, Microsoft has insinuated that CURRENT_TIMEZONE() will be ported to earlier versions of SQL Server, but this doesn’t seem to have happened as of this writing.

In the meantime, you can try the following code.

DECLARE @TimeZone VARCHAR(50)
EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
'SYSTEM\CurrentControlSet\Control\TimeZoneInformation',
'TimeZoneKeyName',@TimeZone OUT
SELECT @TimeZone

Result:

UTC

I ran that on the same instance of SQL Server 2017 that doesn’t support CURRENT_TIMEZONE(), and it worked just fine.

Obviously, your result will depend on where your server is located (or at least, what time zone it has been configured for). Here’s what I get if I run this statement on another server:

W. Europe Standard Time

SQL Server also has a system view that enables you to return a list of supported time zones, that you could use to cross-check your results here.