SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 How to sabe GetDate() in Eastern TimeZone
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

asp__developer
Posting Yak Master

108 Posts

Posted - 06/18/2013 :  17:00:20  Show Profile  Reply with Quote
I have default value in a column as "GetDate()" but the time it saves is the server time on which the database is sitting.

As database is hosted in different time zone, when I see the values, I don't get correct time as I want time to be saved in eastern standard time zone.

any help ?

James K
Flowing Fount of Yak Knowledge

3742 Posts

Posted - 06/18/2013 :  18:04:48  Show Profile  Reply with Quote
Store the time in UTC (using GETUTCDATE() instead of GETDATE()). Then, depending on whether it is daylight savings time or standard time, subtract 4 or five hours. Now it is daylight savings time, so you would do this to get Eastern Daylight Time:
DATEADD(hh,-4,GETUTCDATE())
If you have a server that is set up to adjust for the daylight and standard times in eastern time zone , you can convert from UTC to Eastern without having to hardcode 4 or 5 like this:
DATEADD(hh,DATEDIFF(hh,GETUTCDATE(),GETDATE()),YourUTCDateColumn)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000