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
Solved

MSSQL timezone specific date

Posted on 2008-06-24
5
2,003 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

809 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