?
Solved

MSSQL timezone specific date

Posted on 2008-06-24
5
Medium Priority
?
2,013 Views
Last Modified: 2008-08-05
Hi Guys,

I would like to know if i get MSSQL to return the current time in a specific timezone.

I would like a function like this :

castFromServer ( getDate , "the_timezone_I_am_after"  ).

I have goggled a few resources to no avail.

Any assistance is greatly appreciated.

Cheers,
0
Comment
Question by:sydron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 19

Accepted Solution

by:
frankytee earned 1000 total points
ID: 21862066
i'm not aware of any built in timezone calculator in sql. you'll have to create a "lookup" table with schema like:
City
Country
GMT (time relative to Greenwich Mean Time)
TimeRelativeToLocalTime - optional numeric field- like +5 hours, -9 etc

then join this table on the city country to get the GMT or relative time to your local time.
google to get a site which shows all the major cities and their timezones to build your table.
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 21862407
Hello sydron,

Building on frankytee's response, take care to account for Daylight / Summer Time.  Windows has some
APIs that convert local time to GMT and vice versa; you may be able to exploit that using the new SQL
Server design studio...

Regards,

Patrick
0
 
LVL 25

Expert Comment

by:DBAduck - Ben Miller
ID: 21862718
Along all the lines.  you would have to be able to get the timezone offset in hours that it represents.
You can get the Hours offset by using

DATEDIFF(hh, getdate(), getutcdate())

This is the amount of hours you are behind GMT, then you would keep that information and use it.

0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 21864501
dbaduck,

dbaduck said:
>>DATEDIFF(hh, getdate(), getutcdate())

Small tweak: if you are going to use DATEDIFF, which makes sense, it is better to use minutes instead
of hours: some time zones have a bias on the half hour, such as in India.  You would also still have to know
whether Daylight Time or Summer Time is in effect, and the rules of course vary widely across
jurisdictions.

Regards,

Patrick
0
 

Author Comment

by:sydron
ID: 21903813
Damn, i thought this would be easier and that MSSQL would have something for this.

Thanks for your help guys...You have lead me in the right direction. I will try the ideas out and get  back to you.
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question