Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 How to sabe GetDate() in Eastern TimeZone

Author  Topic 

asp__developer
Posting Yak Master

108 Posts

Posted - 2013-06-18 : 17:00:20
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
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-06-18 : 18:04:48
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
   

- Advertisement -