Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting result in local time from UTC

Status
Not open for further replies.

rookiesql

Technical User
Jul 10, 2003
14
0
0
SE
Hi!
I am retreiving data from a MS SQL 2000 DB to my EXCEL spreadsheet and this goes well using a SQL query from inside EXCEL. However, I have discovered that the returned data for timestamps is in UTC format while my time zone is CET. I scanned the web for info and found that there is an expression like SELECT ....AT TIME ZONE ...
However, I couldn't get that to work in my SQL query. In my query I want to retrieve a column T1.received_date in local time format.
Has anybody been doing these conversions from UTC and knows how the SQL statement should be written?
Regards
Anders
 
GETUTCDATE() is the equivelant of GETDATE().

But to convert your datetime field from UTC to local time, you'll need to script it:

SELECT DATEADD(hour, -1, t1.received_date)

That will subtract one hour from the t1.received_date field. You can make it a positive or negative number depending on the difference between your local time and UTC.

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top