0

Following are the timezone values :

SELECT * FROM sys.time_zone_info

In Javascript, how to populate and match the timezone at DB for calculation? I also have multiple timezones, also need to work in all browsers

Daylight saving also needs to be considered.

I need a dropdown at client side for timezone and that timezone should work with SQL server timezone info, so I can use the following query,

SELECT CONVERT(datetime,'20160101 00:00') AT TIME ZONE 'Cen. Australia Standard Time';

How can I auto select drop down base on browser timezone ?

TAbdiukov
  • 1,185
  • 3
  • 12
  • 25
Furqan Misarwala
  • 1,743
  • 6
  • 26
  • 53
  • What exactly is the issue you're trying to solve? It's not clear from the description unfortunately. Please provide some more details. See [ask] and [mcve] for guidelines on writing a question with high chances of being solved. – Horia Coman Jun 10 '18 at 06:18
  • As a general rule of thumb, you should be storing and working with times in a "foolproof" format such as [unix timestamps](https://en.wikipedia.org/wiki/Unix_time) and only use timezone info when displaying data to users - so in the outermost layers of your application. – Horia Coman Jun 10 '18 at 06:19
  • I need a dropdown at client side for timezone and that timezone should work with sql server timezone info, so I can use SELECT CONVERT(datetime,'20160101 00:00') AT TIME ZONE 'Cen. Australia Standard Time'; and it is considering daylight saving, my issue is how can I auto select drop down base on browser timezone ? – Furqan Misarwala Jun 10 '18 at 06:21

1 Answers1

0

To get the client's time zone name in javascript, one method is with Intl.DateTimeFormat().resolvedOptions().timeZone as detailed in this thread. See this for browser support.

You'll also need a mapping table to associate the IANA timezone canonical name to the Windows time zone name in sys.time_zone_info for use in the AT TIME ZONE clause of the T-SQL CONVERT function. This mapping table can be used for the dropdown as well.

Dan Guzman
  • 43,250
  • 3
  • 46
  • 71