Tuesday, February 14, 2012

Convert GMT to Local Timezone

I've got the following to convert my seconds field to date/hours, but
now I'd like to convert the NewDate to local time.
Select DATEADD(ss, LastOccurTime, '19700101') as NewDate,
LastOccurTime
Found this on the newsgroup, but I need to go the other way:
SELECT DATEADD(HOUR, DATEDIFF(HOUR, GETDATE(), GETUTCDATE()),
GETDATE())
Suggestions/help are greatly appreciated!
Thanks,
Hank> Found this on the newsgroup, but I need to go the other way:
> SELECT DATEADD(HOUR, DATEDIFF(HOUR, GETDATE(), GETUTCDATE()),
> GETDATE())
How about just swapping GETDATE() and GETUTCDATE() inside DATEDIFF()? This
makes the DATEADD perform the inverse operation.
SELECT DATEADD(HOUR, DATEDIFF(HOUR, GETUTCDATE(), GETDATE()), GETDATE())
An example of exactly what you expect to see would be helpful.

No comments:

Post a Comment