Solved

MSSQL timezone specific date

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Insert parts by customer 12 34
what are the unique tables in SQL master database 5 62
sql server tables from access 18 22
Query to capture 5 and 9 digit zip code? 4 21
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.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

810 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