How to Convert a TimeZone name/id from Java to the format recognized by SQL Server / Windows
Hey Folks,
We store timezone IDs from java.util.TimeZone, and now we want to use them with SQL Server (2019)'s AT TIMEZONE function. The problem is, the Java name for the timezone is not the same as the name SQL server wants.
For example, we store the timezone ID from Java 'Australia/Adelaide'. We can get the full name via java.util.TimeZone.getTimeZone('Australia/Adelaide').getDisplayName(), which returns 'Australian Central Standard Time (South Australia)'.
But.... SQL Server wants 'Australian Central Standard Time' and throws an error when using the string returned from Java.
--- this works
select datetime AT TIME ZONE 'Pacific Standard Time' AT TIME ZONE 'Australian Central Standard' AS datetime_TimeZone
-- this fails
select datetime AT TIME ZONE 'Pacific Standard Time' AT TIME ZONE 'Australian Central Standard Time (South Australia)' AS datetime_TimeZone
Note, our dates are stored in PST and there is no way to easily change that now. We just need to be able to convert Java's name of the timezone to the one SQL server expects which I believe is based on the window registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
Has anyone had to deal with this or have any idea?
