SQL Interview: 68 Converting to local time zones

SQL Interview: 68 Converting to local time zones

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.

Section: Development Level: Medium

Question:

You are working with an Azure SQL Database. When you display dates and times, you notice that they do not match your local time zone of CEST.

Can you change the server settings to Central European Standard Time (CEST)?

If not, how can you show the current local time? (NOTE: the code should allow for time changes if daylight saving time applies for part of the year)

Answer:

You currently cannot set a local time zone for an Azure SQL Database.

When you query the current date and time, you can use the AT TIMEZONE option of the CAST function, to change to the required timezone.

SELECT CAST(SYSDATETIME() AT TIME ZONE 'Central European Standard Time');

If the time zone supports daylight saving time, it will automatically use the correct value.

2025-08-04