Solved

MSSQL timezone specific date

Posted on 2008-06-24
5
1,995 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
5 Comments
 
LVL 19

Accepted Solution

by:
frankytee earned 250 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 92

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 24

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 92

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now