0

Using SQL Server, How can I convert the time from the database (UTC) to the user's local timezone?

Their timezone isn't stored in the database, so I have to use an external way to convert it (User's local time/browser timezone).

If anyone could help, that would be great. Thanks.

Felix
  • 1
  • 1
  • 1
    Don't try to solve this down in the database. The user isn't pointing their browser directly at a SQL Server instance - there's code running elsewhere, and that code almost certainly has better facilities for manipulating datetime data. – Damien_The_Unbeliever Jun 13 '14 at 07:49

3 Answers3

0

I think you'll have to just convert the input into the local user's timezone before inserting it into the SQL Server.

Or maybe you could try something like this

Community
  • 1
  • 1
Trent
  • 15
  • 6
0

SQL Server will be of very little help here.

If you totally don't know the exact time zone of the end user, you'll have to do client-side conversion with JavaScript:

Community
  • 1
  • 1
Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288
0

If dealing with client timezone, you need to parse date/time at the browser.

I would recommend the MomentJs library

cloakedninjas
  • 4,007
  • 2
  • 31
  • 45