44

My local development server is in the Middle East, but my production server is in the UK.

I need to show the date to the user in their time zone. For example, if a user is in Saudi Arabia then I need to show the time according to Saudi Arabia format.

Should I create a new database table called TimeZone and save the Time in UTC?

5
  • Effectively Converting dates between UTC and Local (ie. PST) time in SQL 2005 http://stackoverflow.com/questions/24797/effectively-converting-dates-between-utc-and-local-ie-pst-time-in-sql-2005 – mehdi Apr 7 '13 at 9:29
  • Is this a web application, or desktop application, or ...? How this gets implemented varies greatly by the client delivery mechanism, because what you need is dependent on the client side. – Jon Seigel Apr 7 '13 at 16:46
  • This web as well as native mobile. Yes this effect different clients differently. – user960567 Apr 7 '13 at 17:16
  • 1
    Seems like your question is not just about database itself, but involves application development too. This Stack Overflow question is a must-read for you then: Daylight saving time and Timezone best practices – Gan Jun 13 '13 at 11:23
  • Do it the way Windows shows you the current time, as well as the Created date, and Last modified date of files: Store everything as UTC, and format the time for display based on the timezone of the user's PC/device. Not only does that include showing in "local" time, but also using their "local" datetime format. E.g. 2021/3/6 4:01 PM22/07/42 19:03:13 ص for the ar-SA locale. If your web-site is showing dates based on the locale of your web-server: you're doing it wrong. – Ian Boyd Mar 6 at 16:06
56

There's no quick fix for this, unfortunately. Internationalization of an application should be part of the very first design discussions, as it really goes to the core of a lot of different areas, including date/time comparisons and output formatting.

Anyways, to get on the track of Doing It Right, it's essential to store the time zone information with the time. In other words, realizing that the date/time 20130407 14:50 is meaningless without either (a) including the time zone's then-current UTC offset(note 1), or (b) ensuring that all logic inserting these values first converts to a certain fixed offset (most likely 0). Without either of those things, two given time values are incomparable, and the data is corrupt. (The latter method is playing with fire(note 2), by the way; don't do that.)

In SQL Server 2008+, you can store the offset with the time directly by using the datetimeoffset data type. (For completeness, in 2005 and before, I would add a second column to store the then-current UTC offset value (in minutes).)

This makes it easy for a desktop-type application, as these platforms normally have mechanisms to automatically convert a date/time + time zone to a local time and then format for output, all based on the user's regional settings.

For the web, which is an inherently disconnected architecture, even with the back-end data set up properly, it's more complex because you need information about the client to be able to do the conversion and/or formatting. This is usually done via user preference settings (the application converts/formats things before output), or simply showing things with the same fixed format and time zone offset for everyone (which is what the Stack Exchange platform currently does).

You can see how if the back-end data is not set up properly, very quickly it's going to get complicated and hacky. I would not recommend going down any of those paths because you'll just end up with more problems down the line.

Note 1:

A timezone's UTC offset is not fixed: consider daylight savings where a zone's UTC offset varies by plus or minus an hour. Also zones' daylight savings dates vary on a regular basis. So using datetimeoffset (or a composite of local time and UTC offset at that time) results in maximum information recovery.

Note 2:

It's about controlling data inputs. While there's no fool-proof way to validate incoming values, it's better to enforce a simple standard that doesn't involve computations. If a public API expects a data type that includes an offset, that requirement will be clear to the caller.

If that wasn't the case, the caller has to rely on documentation (if they read it), or the computation is done incorrectly, etc. There are fewer failure/bug modes when requiring an offset, in particular for a distributed system (or even just web/database on separate servers as the case here).

Storing the offset anyway kills two birds with one stone; and even if that isn't required now, it makes the possibility available later on if necessary. True it takes up more storage, but I think it's worth the trade-off because the data is lost if it's never recorded in the first place.

3
  • 3
    As I understand it an offset is not the same as timezone... times stored in datetimeoffset lose information like daylight savings time awareness... More info: stackoverflow.com/tags/timezone/info – Peter McEvoy Nov 10 '15 at 16:25
  • 3
    @PeterMcEvoy DST has no relevance here. datetimeoffset means "this is the local time of the user/computer when the thing happened" - we don't need to know if DST was in effect or not, because the given UTC offset is always there (embedded within the datetimeoffset value). – Dai Jun 15 '16 at 5:27
  • Don't conflate "public API" with decisions about how to store internally. The public API could specify that an offset is expected. Internally, datetimes could (still) always be stored in UTC+0. Best of both worlds, IMHO. Storing an offset with each datetime risks offset getting separated from datetime. And harder to sort by time. Also you'll end up converting to/from a local time offset that may be different than the original event time offset. E.g. event at facility elsewhere. Don't complicate that by storing the offset; offset is dynamic, depending on POV. OTOH your approach is valid too – ToolmakerSteve Apr 1 '20 at 1:03
16

I have developed a comprehensive solution for time zone conversion in SQL Server. See SQL Server Time Zone Support on GitHub.

It properly handles conversions between time zones, and to and from UTC, including daylight saving time.

It is similar in concept to the "T-SQL Toolbox" solution described in adss's answer, but it uses the more common IANA / Olson / TZDB time zones instead of Microsoft's, and it includes utilities to keep the data maintained as new releases of the TZDB come out.

Example usage (to answer the OP):

SELECT Tzdb.UtcToLocal(sysutcdatetime(), 'Asia/Riyadh') as CurrentTimeInSaudiArabia

See the readme on GitHub for additional APIs and detailed explanation.

Also, note that since this is a UDF based solution, it is not designed with performance as the primary objective. It would still be better if this functionality was built in to SQL Server, similarly to how the CONVERT_TZ function exists in Oracle and MySQL.

7

SQL Server made modifications in 2005 onward where the internal timezone is saved in UTC. This was largely due to geo-replication and HA projectors involving log shipping, and having the log shipping times saved in different time zones made it impossible for the old method to restore them.

Thus, saving everything internally in UTC time allowed SQL Server to work well globally. This is one of the reasons why daylight savings is kind of a pain to deal with in Windows, because other MS products such as Outlook also save the date/time internally as UTC and create a offset that needs to be patched.

I work in a company where we have thousands of servers (not MS SQL Servers though, but all kinds of servers) spread out all across the world, and if we didn't specifically force everything to go by UTC, we would all go insane very quickly.

7

I have developed and published the “T-SQL Toolbox” project on codeplex to help anybody who struggles with datetime and timezone handling in SQL Server. It’s open source and completely free to use.

It offers easy datetime conversion UDFs using plain T-SQL with additional configuration tables out of the box.

In your example, you can use the following sample:

SELECT [DateTimeUtil].[UDF_ConvertLocalToLocalByTimezoneIdentifier] (
    'GMT Standard Time', -- the original timezone in which your datetime is stored
    'Middle East Standard Time', -- the target timezone for your user
    '2014-03-30 01:55:00' -- the original datetime you want to convert
)

This will return the converted datetime value for your user.

A list of all supported timezones can be found in table "DateTimeUtil.Timezone" also provided within the T-SQL Toolbox database.

4
  • Such a toolkit would seem to be a great help for a developer. However, a scalar function is a black box to the query optimiser. It means that when I apply your function to a column, the configuration tables you are mentioning will be hit as many times as there are rows in the result set (assuming I use the function in the SELECT clause only). That doesn't seem a nice perspective in terms of performance. I haven't really tested your toolkit, though, so I can't say for sure, that's just a general concern based on what I know. – Andriy M May 23 '14 at 13:13
  • Andriy, sure, you are right from a performance perspective. The UDFs query tables are not designed for mass data operations, but for easy usage. Nevertheless, they perform quite ok up to about 100.000 records on my machine. – adss May 23 '14 at 13:36
  • 2
    If one has to process more records in his use case, and performance matters, you should better think of persisting pre-calculated data. But even then, these UDFs might help to persist the datatime values in the required timzones. – adss May 23 '14 at 13:44
  • From my perspective this issue is not about performance, and more about just getting the basic functionality in there. To be able to return accurate information from a query is the first thing. Working out some temp table to cache things and then refer to that in the query or however you handle it to improve performance comes secondary. – Action Dan Nov 8 '17 at 23:32
1

I might be missing something obvious, but if all you want to do is display the date using the user timezone and language format, the simplest way is to always store the dates in UTC in the database and let the client application convert from UTC to local timezone and use the user regional settings to format the date accordingly.

1
  • For most cases this is correct, but consider daylight saving time. If you record a time in the summer, in the winter it will be shown as a different time. This is a bug that was in Exchange/Outlook for many years frustrating customers for whom the exact time could mean winning or losing a patent. So if that's not what you want, you will need to know what the timezone was at the time this time was recorded. Ideally, you will even know this information for the time at which the time was recorded, as you may need historical information on timezones, which sometimes change. – Arwin May 4 '20 at 9:24
0

little late but for me I resolved by mapping between windows and timezone database.

following SQL result is a mapping. There is a column name SQL_Names apply a join with [sys].[Time_Zone_Info] table to get SQL Time Zone detail below is the sample.

Note: the JSON is not covering all the timezone due to character limits here but you may import a full list from the below links.

try out:

DECLARE @TZ_Json VARCHAR(MAX)
SET @TZ_Json = '[{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Abidjan","TZTerritory":"CI"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Accra","TZTerritory":"GH"},{"SQLName":"E. Africa Standard Time","TZName":"Africa\/Addis_Ababa","TZTerritory":"ET"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Algiers","TZTerritory":"DZ"},{"SQLName":"E. Africa Standard Time","TZName":"Africa\/Asmera","TZTerritory":"ER"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Bamako","TZTerritory":"ML"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Bangui","TZTerritory":"CF"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Banjul","TZTerritory":"GM"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Bissau","TZTerritory":"GW"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Blantyre","TZTerritory":"MW"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Brazzaville","TZTerritory":"CG"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Bujumbura","TZTerritory":"BI"},{"SQLName":"Egypt Standard Time","TZName":"Africa\/Cairo","TZTerritory":"001"},{"SQLName":"Egypt Standard Time","TZName":"Africa\/Cairo","TZTerritory":"EG"},{"SQLName":"Morocco Standard Time","TZName":"Africa\/Casablanca","TZTerritory":"001"},{"SQLName":"Morocco Standard Time","TZName":"Africa\/Casablanca","TZTerritory":"MA"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Conakry","TZTerritory":"GN"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Dakar","TZTerritory":"SN"},{"SQLName":"E. Africa Standard Time","TZName":"Africa\/Dar_es_Salaam","TZTerritory":"TZ"},{"SQLName":"E. Africa Standard Time","TZName":"Africa\/Djibouti","TZTerritory":"DJ"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Douala","TZTerritory":"CM"},{"SQLName":"Morocco Standard Time","TZName":"Africa\/El_Aaiun","TZTerritory":"EH"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Freetown","TZTerritory":"SL"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Gaborone","TZTerritory":"BW"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Harare","TZTerritory":"ZW"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Johannesburg","TZTerritory":"ZA"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Johannesburg","TZTerritory":"001"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Juba","TZTerritory":"SS"},{"SQLName":"E. Africa Standard Time","TZName":"Africa\/Kampala","TZTerritory":"UG"},{"SQLName":"Sudan Standard Time","TZName":"Africa\/Khartoum","TZTerritory":"001"},{"SQLName":"Sudan Standard Time","TZName":"Africa\/Khartoum","TZTerritory":"SD"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Kigali","TZTerritory":"RW"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Kinshasa","TZTerritory":"CD"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Lagos","TZTerritory":"001"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Lagos","TZTerritory":"NG"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Libreville","TZTerritory":"GA"},'
SET @TZ_Json = @TZ_Json + '{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Lome","TZTerritory":"TG"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Luanda","TZTerritory":"AO"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Lubumbashi","TZTerritory":"CD"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Lusaka","TZTerritory":"ZM"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Malabo","TZTerritory":"GQ"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Maputo","TZTerritory":"MZ"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Maseru","TZTerritory":"LS"},{"SQLName":"South Africa Standard Time","TZName":"Africa\/Mbabane","TZTerritory":"SZ"},{"SQLName":"E. Africa Standard Time","TZName":"Africa\/Mogadishu","TZTerritory":"SO"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Monrovia","TZTerritory":"LR"},{"SQLName":"E. Africa Standard Time","TZName":"Africa\/Nairobi","TZTerritory":"001"},{"SQLName":"E. Africa Standard Time","TZName":"Africa\/Nairobi","TZTerritory":"KE"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Ndjamena","TZTerritory":"TD"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Niamey","TZTerritory":"NE"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Nouakchott","TZTerritory":"MR"},{"SQLName":"Greenwich Standard Time","TZName":"Africa\/Ouagadougou","TZTerritory":"BF"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Porto-Novo","TZTerritory":"BJ"},{"SQLName":"Sao Tome Standard Time","TZName":"Africa\/Sao_Tome","TZTerritory":"001"},{"SQLName":"Sao Tome Standard Time","TZName":"Africa\/Sao_Tome","TZTerritory":"ST"},{"SQLName":"Libya Standard Time","TZName":"Africa\/Tripoli","TZTerritory":"001"},{"SQLName":"Libya Standard Time","TZName":"Africa\/Tripoli","TZTerritory":"LY"},{"SQLName":"W. Central Africa Standard Time","TZName":"Africa\/Tunis","TZTerritory":"TN"},{"SQLName":"Namibia Standard Time","TZName":"Africa\/Windhoek","TZTerritory":"001"},{"SQLName":"Namibia Standard Time","TZName":"Africa\/Windhoek","TZTerritory":"NA"},{"SQLName":"Aleutian Standard Time","TZName":"America\/Adak","TZTerritory":"001"},{"SQLName":"Aleutian Standard Time","TZName":"America\/Adak","TZTerritory":"US"},{"SQLName":"Alaskan Standard Time","TZName":"America\/Anchorage","TZTerritory":"001"},{"SQLName":"Alaskan Standard Time","TZName":"America\/Anchorage America\/Juneau America\/Metlakatla America\/Nome America\/Sitka America\/Yakutat","TZTerritory":"US"},{"SQLName":"SA Western Standard Time","TZName":"America\/Anguilla","TZTerritory":"AI"},{"SQLName":"SA Western Standard Time","TZName":"America\/Antigua","TZTerritory":"AG"},{"SQLName":"Tocantins Standard Time","TZName":"America\/Araguaina","TZTerritory":"001"},{"SQLName":"Tocantins Standard Time","TZName":"America\/Araguaina","TZTerritory":"BR"},{"SQLName":"SA Western Standard Time","TZName":"America\/Aruba","TZTerritory":"AW"},{"SQLName":"Paraguay Standard Time","TZName":"America\/Asuncion","TZTerritory":"001"},{"SQLName":"Paraguay Standard Time","TZName":"America\/Asuncion","TZTerritory":"PY"},'
SET @TZ_Json = @TZ_Json + '{"SQLName":"Bahia Standard Time","TZName":"America\/Bahia","TZTerritory":"001"},{"SQLName":"Bahia Standard Time","TZName":"America\/Bahia","TZTerritory":"BR"},{"SQLName":"SA Western Standard Time","TZName":"America\/Barbados","TZTerritory":"BB"},{"SQLName":"Central America Standard Time","TZName":"America\/Belize","TZTerritory":"BZ"},{"SQLName":"SA Western Standard Time","TZName":"America\/Blanc-Sablon","TZTerritory":"CA"},{"SQLName":"SA Pacific Standard Time","TZName":"America\/Bogota","TZTerritory":"CO"},{"SQLName":"SA Pacific Standard Time","TZName":"America\/Bogota","TZTerritory":"001"},{"SQLName":"Argentina Standard Time","TZName":"America\/Buenos_Aires","TZTerritory":"001"},{"SQLName":"Argentina Standard Time","TZName":"America\/Buenos_Aires America\/Argentina\/La_Rioja America\/Argentina\/Rio_Gallegos America\/Argentina\/Salta America\/Argentina\/San_Juan America\/Argentina\/San_Luis America\/Argentina\/Tucuman America\/Argentina\/Ushuaia America\/Catamarca America\/Cordoba America\/Juju","TZTerritory":"AR"},{"SQLName":"Eastern Standard Time (Mexico)","TZName":"America\/Cancun","TZTerritory":"001"},{"SQLName":"Eastern Standard Time (Mexico)","TZName":"America\/Cancun","TZTerritory":"MX"},{"SQLName":"Venezuela Standard Time","TZName":"America\/Caracas","TZTerritory":"001"},{"SQLName":"Venezuela Standard Time","TZName":"America\/Caracas","TZTerritory":"VE"},{"SQLName":"SA Eastern Standard Time","TZName":"America\/Cayenne","TZTerritory":"001"},{"SQLName":"SA Eastern Standard Time","TZName":"America\/Cayenne","TZTerritory":"GF"},{"SQLName":"SA Pacific Standard Time","TZName":"America\/Cayman","TZTerritory":"KY"},{"SQLName":"Central Standard Time","TZName":"America\/Chicago","TZTerritory":"001"},{"SQLName":"Central Standard Time","TZName":"America\/Chicago America\/Indiana\/Knox America\/Indiana\/Tell_City America\/Menominee America\/North_Dakota\/Beulah America\/North_Dakota\/Center America\/North_Dakota\/New_Salem","TZTerritory":"US"},{"SQLName":"Mountain Standard Time (Mexico)","TZName":"America\/Chihuahua","TZTerritory":"001"},{"SQLName":"Mountain Standard Time (Mexico)","TZName":"America\/Chihuahua America\/Mazatlan","TZTerritory":"MX"},{"SQLName":"SA Pacific Standard Time","TZName":"America\/Coral_Harbour","TZTerritory":"CA"},{"SQLName":"Central America Standard Time","TZName":"America\/Costa_Rica","TZTerritory":"CR"},{"SQLName":"US Mountain Standard Time","TZName":"America\/Creston America\/Dawson_Creek America\/Fort_Nelson","TZTerritory":"CA"},{"SQLName":"Central Brazilian Standard Time","TZName":"America\/Cuiaba","TZTerritory":"001"},{"SQLName":"Central Brazilian Standard Time","TZName":"America\/Cuiaba America\/Campo_Grande","TZTerritory":"BR"},{"SQLName":"SA Western Standard Time","TZName":"America\/Curacao","TZTerritory":"CW"},{"SQLName":"UTC","TZName":"America\/Danmarkshavn","TZTerritory":"GL"},{"SQLName":"Mountain Standard Time","TZName":"America\/Denver","TZTerritory":"001"},{"SQLName":"Mountain Standard Time","TZName":"America\/Denver America\/Boise","TZTerritory":"US"},'
SET @TZ_Json = @TZ_Json + '{"SQLName":"SA Western Standard Time","TZName":"America\/Dominica","TZTerritory":"DM"},{"SQLName":"Mountain Standard Time","TZName":"America\/Edmonton America\/Cambridge_Bay America\/Inuvik America\/Yellowknife","TZTerritory":"CA"},{"SQLName":"Central America Standard Time","TZName":"America\/El_Salvador","TZTerritory":"SV"},{"SQLName":"SA Eastern Standard Time","TZName":"America\/Fortaleza America\/Belem America\/Maceio America\/Recife America\/Santarem","TZTerritory":"BR"},{"SQLName":"Greenland Standard Time","TZName":"America\/Godthab","TZTerritory":"001"},{"SQLName":"Greenland Standard Time","TZName":"America\/Godthab","TZTerritory":"GL"},{"SQLName":"Turks And Caicos Standard Time","TZName":"America\/Grand_Turk","TZTerritory":"001"},{"SQLName":"Turks And Caicos Standard Time","TZName":"America\/Grand_Turk","TZTerritory":"TC"},{"SQLName":"SA Western Standard Time","TZName":"America\/Grenada","TZTerritory":"GD"},{"SQLName":"SA Western Standard Time","TZName":"America\/Guadeloupe","TZTerritory":"GP"},{"SQLName":"Central America Standard Time","TZName":"America\/Guatemala","TZTerritory":"GT"},{"SQLName":"Central America Standard Time","TZName":"America\/Guatemala","TZTerritory":"001"},{"SQLName":"SA Pacific Standard Time","TZName":"America\/Guayaquil","TZTerritory":"EC"},{"SQLName":"SA Western Standard Time","TZName":"America\/Guyana","TZTerritory":"GY"},{"SQLName":"Atlantic Standard Time","TZName":"America\/Halifax","TZTerritory":"001"},{"SQLName":"Atlantic Standard Time","TZName":"America\/Halifax America\/Glace_Bay America\/Goose_Bay America\/Moncton","TZTerritory":"CA"},{"SQLName":"Cuba Standard Time","TZName":"America\/Havana","TZTerritory":"001"},{"SQLName":"Cuba Standard Time","TZName":"America\/Havana","TZTerritory":"CU"},{"SQLName":"US Mountain Standard Time","TZName":"America\/Hermosillo","TZTerritory":"MX"},{"SQLName":"US Eastern Standard Time","TZName":"America\/Indianapolis","TZTerritory":"001"},{"SQLName":"US Eastern Standard Time","TZName":"America\/Indianapolis America\/Indiana\/Marengo America\/Indiana\/Vevay","TZTerritory":"US"},{"SQLName":"SA Pacific Standard Time","TZName":"America\/Jamaica","TZTerritory":"JM"},{"SQLName":"SA Western Standard Time","TZName":"America\/Kralendijk","TZTerritory":"BQ"},{"SQLName":"SA Western Standard Time","TZName":"America\/La_Paz","TZTerritory":"BO"},{"SQLName":"SA Western Standard Time","TZName":"America\/La_Paz","TZTerritory":"001"},{"SQLName":"SA Pacific Standard Time","TZName":"America\/Lima","TZTerritory":"PE"},{"SQLName":"Pacific Standard Time","TZName":"America\/Los_Angeles","TZTerritory":"001"},{"SQLName":"Pacific Standard Time","TZName":"America\/Los_Angeles","TZTerritory":"US"},{"SQLName":"SA Western Standard Time","TZName":"America\/Lower_Princes","TZTerritory":"SX"},{"SQLName":"Central America Standard Time","TZName":"America\/Managua","TZTerritory":"NI"},{"SQLName":"SA Western Standard Time","TZName":"America\/Manaus America\/Boa_Vista America\/Porto_Velho","TZTerritory":"BR"},{"SQLName":"SA Western Standard Time","TZName":"America\/Marigot","TZTerritory":"MF"},'
SET @TZ_Json = @TZ_Json + '{"SQLName":"SA Western Standard Time","TZName":"America\/Martinique","TZTerritory":"MQ"},{"SQLName":"Central Standard Time","TZName":"America\/Matamoros","TZTerritory":"MX"},{"SQLName":"Central Standard Time (Mexico)","TZName":"America\/Mexico_City","TZTerritory":"001"},{"SQLName":"Central Standard Time (Mexico)","TZName":"America\/Mexico_City America\/Bahia_Banderas America\/Merida America\/Monterrey","TZTerritory":"MX"},{"SQLName":"Saint Pierre Standard Time","TZName":"America\/Miquelon","TZTerritory":"001"},{"SQLName":"Saint Pierre Standard Time","TZName":"America\/Miquelon","TZTerritory":"PM"},{"SQLName":"Montevideo Standard Time","TZName":"America\/Montevideo","TZTerritory":"001"},{"SQLName":"Montevideo Standard Time","TZName":"America\/Montevideo","TZTerritory":"UY"},{"SQLName":"SA Western Standard Time","TZName":"America\/Montserrat","TZTerritory":"MS"},{"SQLName":"Eastern Standard Time","TZName":"America\/Nassau","TZTerritory":"BS"},{"SQLName":"Eastern Standard Time","TZName":"America\/New_York","TZTerritory":"001"},{"SQLName":"Eastern Standard Time","TZName":"America\/New_York America\/Detroit America\/Indiana\/Petersburg America\/Indiana\/Vincennes America\/Indiana\/Winamac America\/Kentucky\/Monticello America\/Louisville","TZTerritory":"US"},{"SQLName":"UTC-02","TZName":"America\/Noronha","TZTerritory":"BR"},{"SQLName":"Mountain Standard Time","TZName":"America\/Ojinaga","TZTerritory":"MX"},{"SQLName":"SA Pacific Standard Time","TZName":"America\/Panama","TZTerritory":"PA"},{"SQLName":"SA Eastern Standard Time","TZName":"America\/Paramaribo","TZTerritory":"SR"},{"SQLName":"US Mountain Standard Time","TZName":"America\/Phoenix","TZTerritory":"001"},{"SQLName":"US Mountain Standard Time","TZName":"America\/Phoenix","TZTerritory":"US"},{"SQLName":"SA Western Standard Time","TZName":"America\/Port_of_Spain","TZTerritory":"TT"},{"SQLName":"Haiti Standard Time","TZName":"America\/Port-au-Prince","TZTerritory":"001"},{"SQLName":"Haiti Standard Time","TZName":"America\/Port-au-Prince","TZTerritory":"HT"},{"SQLName":"SA Western Standard Time","TZName":"America\/Puerto_Rico","TZTerritory":"PR"},{"SQLName":"Magallanes Standard Time","TZName":"America\/Punta_Arenas","TZTerritory":"001"},{"SQLName":"Magallanes Standard Time","TZName":"America\/Punta_Arenas","TZTerritory":"CL"},{"SQLName":"Canada Central Standard Time","TZName":"America\/Regina","TZTerritory":"001"},{"SQLName":"Canada Central Standard Time","TZName":"America\/Regina America\/Swift_Current","TZTerritory":"CA"},{"SQLName":"SA Pacific Standard Time","TZName":"America\/Rio_Branco America\/Eirunepe","TZTerritory":"BR"},{"SQLName":"Pacific SA Standard Time","TZName":"America\/Santiago","TZTerritory":"001"},{"SQLName":"Pacific SA Standard Time","TZName":"America\/Santiago","TZTerritory":"CL"},{"SQLName":"SA Western Standard Time","TZName":"America\/Santo_Domingo","TZTerritory":"DO"},{"SQLName":"E. South America Standard Time","TZName":"America\/Sao_Paulo","TZTerritory":"001"},{"SQLName":"E. South America Standard Time","TZName":"America\/Sao_Paulo","TZTerritory":"BR"},'
SET @TZ_Json = @TZ_Json + '{"SQLName":"Azores Standard Time","TZName":"America\/Scoresbysund","TZTerritory":"GL"},{"SQLName":"SA Western Standard Time","TZName":"America\/St_Barthelemy","TZTerritory":"BL"},{"SQLName":"Newfoundland Standard Time","TZName":"America\/St_Johns","TZTerritory":"001"},{"SQLName":"Newfoundland Standard Time","TZName":"America\/St_Johns","TZTerritory":"CA"},{"SQLName":"SA Western Standard Time","TZName":"America\/St_Kitts","TZTerritory":"KN"},{"SQLName":"SA Western Standard Time","TZName":"America\/St_Lucia","TZTerritory":"LC"},{"SQLName":"SA Western Standard Time","TZName":"America\/St_Thomas","TZTerritory":"VI"},{"SQLName":"SA Western Standard Time","TZName":"America\/St_Vincent","TZTerritory":"VC"},{"SQLName":"Central America Standard Time","TZName":"America\/Tegucigalpa","TZTerritory":"HN"},{"SQLName":"Atlantic Standard Time","TZName":"America\/Thule","TZTerritory":"GL"},{"SQLName":"Pacific Standard Time (Mexico)","TZName":"America\/Tijuana","TZTerritory":"001"},{"SQLName":"Pacific Standard Time (Mexico)","TZName":"America\/Tijuana America\/Santa_Isabel","TZTerritory":"MX"},{"SQLName":"Eastern Standard Time","TZName":"America\/Toronto America\/Iqaluit America\/Montreal America\/Nipigon America\/Pangnirtung America\/Thunder_Bay","TZTerritory":"CA"},{"SQLName":"SA Western Standard Time","TZName":"America\/Tortola","TZTerritory":"VG"},{"SQLName":"Pacific Standard Time","TZName":"America\/Vancouver","TZTerritory":"CA"},{"SQLName":"Yukon Standard Time","TZName":"America\/Whitehorse","TZTerritory":"001"},{"SQLName":"Yukon Standard Time","TZName":"America\/Whitehorse America\/Dawson","TZTerritory":"CA"},{"SQLName":"Central Standard Time","TZName":"America\/Winnipeg America\/Rainy_River America\/Rankin_Inlet America\/Resolute","TZTerritory":"CA"},{"SQLName":"Central Pacific Standard Time","TZName":"Antarctica\/Casey","TZTerritory":"AQ"},{"SQLName":"SE Asia Standard Time","TZName":"Antarctica\/Davis","TZTerritory":"AQ"},{"SQLName":"West Pacific Standard Time","TZName":"Antarctica\/DumontDUrville","TZTerritory":"AQ"},{"SQLName":"West Asia Standard Time","TZName":"Antarctica\/Mawson","TZTerritory":"AQ"},{"SQLName":"New Zealand Standard Time","TZName":"Antarctica\/McMurdo","TZTerritory":"AQ"},{"SQLName":"SA Eastern Standard Time","TZName":"Antarctica\/Rothera Antarctica\/Palmer","TZTerritory":"AQ"},{"SQLName":"E. Africa Standard Time","TZName":"Antarctica\/Syowa","TZTerritory":"AQ"},{"SQLName":"Central Asia Standard Time","TZName":"Antarctica\/Vostok","TZTerritory":"AQ"},{"SQLName":"W. Europe Standard Time","TZName":"Arctic\/Longyearbyen","TZTerritory":"SJ"},{"SQLName":"Arab Standard Time","TZName":"Asia\/Aden","TZTerritory":"YE"},{"SQLName":"Central Asia Standard Time","TZName":"Asia\/Almaty","TZTerritory":"001"},{"SQLName":"Central Asia Standard Time","TZName":"Asia\/Almaty Asia\/Qostanay","TZTerritory":"KZ"},{"SQLName":"Jordan Standard Time","TZName":"Asia\/Amman","TZTerritory":"001"},{"SQLName":"Jordan Standard Time","TZName":"Asia\/Amman","TZTerritory":"JO"},{"SQLName":"West Asia Standard Time","TZName":"Asia\/Ashgabat","TZTerritory":"TM"},'
SET @TZ_Json = @TZ_Json + '{"SQLName":"Arabic Standard Time","TZName":"Asia\/Baghdad","TZTerritory":"001"},{"SQLName":"Arabic Standard Time","TZName":"Asia\/Baghdad","TZTerritory":"IQ"},{"SQLName":"Arab Standard Time","TZName":"Asia\/Bahrain","TZTerritory":"BH"},{"SQLName":"Azerbaijan Standard Time","TZName":"Asia\/Baku","TZTerritory":"001"},{"SQLName":"Azerbaijan Standard Time","TZName":"Asia\/Baku","TZTerritory":"AZ"},{"SQLName":"SE Asia Standard Time","TZName":"Asia\/Bangkok","TZTerritory":"TH"},{"SQLName":"SE Asia Standard Time","TZName":"Asia\/Bangkok","TZTerritory":"001"},{"SQLName":"Altai Standard Time","TZName":"Asia\/Barnaul","TZTerritory":"001"},{"SQLName":"Altai Standard Time","TZName":"Asia\/Barnaul","TZTerritory":"RU"},{"SQLName":"Middle East Standard Time","TZName":"Asia\/Beirut","TZTerritory":"001"},{"SQLName":"Middle East Standard Time","TZName":"Asia\/Beirut","TZTerritory":"LB"},{"SQLName":"Central Asia Standard Time","TZName":"Asia\/Bishkek","TZTerritory":"KG"},{"SQLName":"Singapore Standard Time","TZName":"Asia\/Brunei","TZTerritory":"BN"},{"SQLName":"India Standard Time","TZName":"Asia\/Calcutta","TZTerritory":"001"},{"SQLName":"India Standard Time","TZName":"Asia\/Calcutta","TZTerritory":"IN"},{"SQLName":"Transbaikal Standard Time","TZName":"Asia\/Chita","TZTerritory":"001"},{"SQLName":"Transbaikal Standard Time","TZName":"Asia\/Chita","TZTerritory":"RU"},{"SQLName":"Sri Lanka Standard Time","TZName":"Asia\/Colombo","TZTerritory":"001"},{"SQLName":"Sri Lanka Standard Time","TZName":"Asia\/Colombo","TZTerritory":"LK"},{"SQLName":"Syria Standard Time","TZName":"Asia\/Damascus","TZTerritory":"001"},{"SQLName":"Syria Standard Time","TZName":"Asia\/Damascus","TZTerritory":"SY"},{"SQLName":"Bangladesh Standard Time","TZName":"Asia\/Dhaka","TZTerritory":"001"},{"SQLName":"Bangladesh Standard Time","TZName":"Asia\/Dhaka","TZTerritory":"BD"},{"SQLName":"Tokyo Standard Time","TZName":"Asia\/Dili","TZTerritory":"TL"},{"SQLName":"Arabian Standard Time","TZName":"Asia\/Dubai","TZTerritory":"001"},{"SQLName":"Arabian Standard Time","TZName":"Asia\/Dubai","TZTerritory":"AE"},{"SQLName":"West Asia Standard Time","TZName":"Asia\/Dushanbe","TZTerritory":"TJ"},{"SQLName":"West Bank Standard Time","TZName":"Asia\/Hebron","TZTerritory":"001"},{"SQLName":"West Bank Standard Time","TZName":"Asia\/Hebron Asia\/Gaza","TZTerritory":"PS"},{"SQLName":"China Standard Time","TZName":"Asia\/Hong_Kong","TZTerritory":"HK"},{"SQLName":"W. Mongolia Standard Time","TZName":"Asia\/Hovd","TZTerritory":"001"},{"SQLName":"W. Mongolia Standard Time","TZName":"Asia\/Hovd","TZTerritory":"MN"},{"SQLName":"North Asia East Standard Time","TZName":"Asia\/Irkutsk","TZTerritory":"001"},{"SQLName":"North Asia East Standard Time","TZName":"Asia\/Irkutsk","TZTerritory":"RU"},{"SQLName":"SE Asia Standard Time","TZName":"Asia\/Jakarta Asia\/Pontianak","TZTerritory":"ID"},{"SQLName":"Tokyo Standard Time","TZName":"Asia\/Jayapura","TZTerritory":"ID"},{"SQLName":"Israel Standard Time","TZName":"Asia\/Jerusalem","TZTerritory":"001"},{"SQLName":"Israel Standard Time","TZName":"Asia\/Jerusalem","TZTerritory":"IL"},'
SET @TZ_Json = @TZ_Json + '{"SQLName":"Afghanistan Standard Time","TZName":"Asia\/Kabul","TZTerritory":"001"},{"SQLName":"Afghanistan Standard Time","TZName":"Asia\/Kabul","TZTerritory":"AF"},{"SQLName":"Russia Time Zone 11","TZName":"Asia\/Kamchatka","TZTerritory":"001"},{"SQLName":"Russia Time Zone 11","TZName":"Asia\/Kamchatka Asia\/Anadyr","TZTerritory":"RU"},{"SQLName":"Pakistan Standard Time","TZName":"Asia\/Karachi","TZTerritory":"001"},{"SQLName":"Pakistan Standard Time","TZName":"Asia\/Karachi","TZTerritory":"PK"},{"SQLName":"Nepal Standard Time","TZName":"Asia\/Katmandu","TZTerritory":"001"},{"SQLName":"Nepal Standard Time","TZName":"Asia\/Katmandu","TZTerritory":"NP"},{"SQLName":"North Asia Standard Time","TZName":"Asia\/Krasnoyarsk","TZTerritory":"001"},{"SQLName":"North Asia Standard Time","TZName":"Asia\/Krasnoyarsk Asia\/Novokuznetsk","TZTerritory":"RU"},{"SQLName":"Singapore Standard Time","TZName":"Asia\/Kuala_Lumpur Asia\/Kuching","TZTerritory":"MY"},{"SQLName":"Arab Standard Time","TZName":"Asia\/Kuwait","TZTerritory":"KW"},{"SQLName":"China Standard Time","TZName":"Asia\/Macau","TZTerritory":"MO"},{"SQLName":"Magadan Standard Time","TZName":"Asia\/Magadan","TZTerritory":"001"},{"SQLName":"Magadan Standard Time","TZName":"Asia\/Magadan","TZTerritory":"RU"},{"SQLName":"Singapore Standard Time","TZName":"Asia\/Makassar","TZTerritory":"ID"},{"SQLName":"Singapore Standard Time","TZName":"Asia\/Manila","TZTerritory":"PH"},{"SQLName":"Arabian Standard Time","TZName":"Asia\/Muscat","TZTerritory":"OM"},{"SQLName":"GTB Standard Time","TZName":"Asia\/Nicosia Asia\/Famagusta","TZTerritory":"CY"},{"SQLName":"N. Central Asia Standard Time","TZName":"Asia\/Novosibirsk","TZTerritory":"001"},{"SQLName":"N. Central Asia Standard Time","TZName":"Asia\/Novosibirsk","TZTerritory":"RU"},{"SQLName":"Omsk Standard Time","TZName":"Asia\/Omsk","TZTerritory":"001"},{"SQLName":"Omsk Standard Time","TZName":"Asia\/Omsk","TZTerritory":"RU"},{"SQLName":"West Asia Standard Time","TZName":"Asia\/Oral Asia\/Aqtau Asia\/Aqtobe Asia\/Atyrau","TZTerritory":"KZ"},{"SQLName":"SE Asia Standard Time","TZName":"Asia\/Phnom_Penh","TZTerritory":"KH"},{"SQLName":"North Korea Standard Time","TZName":"Asia\/Pyongyang","TZTerritory":"001"},{"SQLName":"North Korea Standard Time","TZName":"Asia\/Pyongyang","TZTerritory":"KP"},{"SQLName":"Arab Standard Time","TZName":"Asia\/Qatar","TZTerritory":"QA"},{"SQLName":"Qyzylorda Standard Time","TZName":"Asia\/Qyzylorda","TZTerritory":"001"},{"SQLName":"Qyzylorda Standard Time","TZName":"Asia\/Qyzylorda","TZTerritory":"KZ"},{"SQLName":"Myanmar Standard Time","TZName":"Asia\/Rangoon","TZTerritory":"001"},{"SQLName":"Myanmar Standard Time","TZName":"Asia\/Rangoon","TZTerritory":"MM"},{"SQLName":"Arab Standard Time","TZName":"Asia\/Riyadh","TZTerritory":"SA"},{"SQLName":"Arab Standard Time","TZName":"Asia\/Riyadh","TZTerritory":"001"},{"SQLName":"SE Asia Standard Time","TZName":"Asia\/Saigon","TZTerritory":"VN"},{"SQLName":"Sakhalin Standard Time","TZName":"Asia\/Sakhalin","TZTerritory":"001"},{"SQLName":"Sakhalin Standard Time","TZName":"Asia\/Sakhalin","TZTerritory":"RU"},'
SET @TZ_Json = @TZ_Json + '{"SQLName":"Korea Standard Time","TZName":"Asia\/Seoul","TZTerritory":"001"},{"SQLName":"Korea Standard Time","TZName":"Asia\/Seoul","TZTerritory":"KR"},{"SQLName":"China Standard Time","TZName":"Asia\/Shanghai","TZTerritory":"001"},{"SQLName":"China Standard Time","TZName":"Asia\/Shanghai","TZTerritory":"CN"},{"SQLName":"Singapore Standard Time","TZName":"Asia\/Singapore","TZTerritory":"SG"},{"SQLName":"Singapore Standard Time","TZName":"Asia\/Singapore","TZTerritory":"001"},{"SQLName":"Russia Time Zone 10","TZName":"Asia\/Srednekolymsk","TZTerritory":"001"},{"SQLName":"Russia Time Zone 10","TZName":"Asia\/Srednekolymsk","TZTerritory":"RU"},{"SQLName":"Taipei Standard Time","TZName":"Asia\/Taipei","TZTerritory":"001"},{"SQLName":"Taipei Standard Time","TZName":"Asia\/Taipei","TZTerritory":"TW"},{"SQLName":"West Asia Standard Time","TZName":"Asia\/Tashkent","TZTerritory":"001"},{"SQLName":"West Asia Standard Time","TZName":"Asia\/Tashkent Asia\/Samarkand","TZTerritory":"UZ"},{"SQLName":"Georgian Standard Time","TZName":"Asia\/Tbilisi","TZTerritory":"001"},{"SQLName":"Georgian Standard Time","TZName":"Asia\/Tbilisi","TZTerritory":"GE"},{"SQLName":"Iran Standard Time","TZName":"Asia\/Tehran","TZTerritory":"001"},{"SQLName":"Iran Standard Time","TZName":"Asia\/Tehran","TZTerritory":"IR"},{"SQLName":"Bangladesh Standard Time","TZName":"Asia\/Thimphu","TZTerritory":"BT"},{"SQLName":"Tokyo Standard Time","TZName":"Asia\/Tokyo","TZTerritory":"001"},{"SQLName":"Tokyo Standard Time","TZName":"Asia\/Tokyo","TZTerritory":"JP"},{"SQLName":"Tomsk Standard Time","TZName":"Asia\/Tomsk","TZTerritory":"001"},{"SQLName":"Tomsk Standard Time","TZName":"Asia\/Tomsk","TZTerritory":"RU"},{"SQLName":"Ulaanbaatar Standard Time","TZName":"Asia\/Ulaanbaatar","TZTerritory":"001"},{"SQLName":"Ulaanbaatar Standard Time","TZName":"Asia\/Ulaanbaatar Asia\/Choibalsan","TZTerritory":"MN"},{"SQLName":"Central Asia Standard Time","TZName":"Asia\/Urumqi","TZTerritory":"CN"},{"SQLName":"SE Asia Standard Time","TZName":"Asia\/Vientiane","TZTerritory":"LA"},{"SQLName":"Vladivostok Standard Time","TZName":"Asia\/Vladivostok","TZTerritory":"001"},{"SQLName":"Vladivostok Standard Time","TZName":"Asia\/Vladivostok Asia\/Ust-Nera","TZTerritory":"RU"},{"SQLName":"Yakutsk Standard Time","TZName":"Asia\/Yakutsk","TZTerritory":"001"},{"SQLName":"Yakutsk Standard Time","TZName":"Asia\/Yakutsk Asia\/Khandyga","TZTerritory":"RU"},{"SQLName":"Ekaterinburg Standard Time","TZName":"Asia\/Yekaterinburg","TZTerritory":"001"},{"SQLName":"Ekaterinburg Standard Time","TZName":"Asia\/Yekaterinburg","TZTerritory":"RU"},{"SQLName":"Caucasus Standard Time","TZName":"Asia\/Yerevan","TZTerritory":"001"},{"SQLName":"Caucasus Standard Time","TZName":"Asia\/Yerevan","TZTerritory":"AM"},{"SQLName":"Azores Standard Time","TZName":"Atlantic\/Azores","TZTerritory":"PT"},{"SQLName":"Azores Standard Time","TZName":"Atlantic\/Azores","TZTerritory":"001"},{"SQLName":"Atlantic Standard Time","TZName":"Atlantic\/Bermuda","TZTerritory":"BM"},{"SQLName":"GMT Standard Time","TZName":"Atlantic\/Canary","TZTerritory":"ES"}]'

/* To Get the full list refer windows-time-zone http link below */

SELECT j.TZName,j.TZTerritory, j.SQLName, tz.[current_utc_offset],tz.[is_currently_dst]
FROM (
    SELECT SQLName,TZName,TZTerritory FROM  OPENJSON(@TZ_Json)
    WITH (
        SQLName VARCHAR(200) '$.SQLName',
        TZName VARCHAR(200) '$.TZName',
        TZTerritory VARCHAR(200) '$.TZTerritory')
    )j  INNER JOIN sys.[time_zone_info]tz ON j.[SQLName]=tz.[name]

furthermore, refer to the below links:

List of tz database time zones

Windows Timezone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.