azure-sql-databaseazure-sql-serverazure-sql

Azure SQL Convert "Time zone display name" to "Time zone ID"


I am working with the latest version of Azure SQL. I have a series of Time zone display name and want to convert those into Time zone ID. I know SQL server contains both the display name and the id. sys.time_zone_info has all the Time zone ID, but commands like CURRENT_TIMEZONE () output Time zone display name. What I am hoping for is a simple function that takes a string Time zone display name and returns the Time zone ID that name maps to, but I can't find any reference to that. And I can't find a table that actually stores the mapping.

Reference - Time zones in Azure SQL Managed Instance


Solution

  • In sys.time_zone_info, the name is the ID. Not the greatest for normalization purposes.

    If you're using this to have your own internal time zone list for your application, then I think Joseph Xu has the correct answer.

    If you're using this for queries against Azure SQL expecting time zone localization, bear in mind that, according to Azure SQL documentation, the database operates in UTC, and CURRENT_TIMEZONE_ID() will return UTC always.