Link to home
Start Free TrialLog in
Avatar of jbaird123
jbaird123

asked on

Using Local Time Zone wtih SQL Server

I have a date field in an SQL Server 2005 table, and the date is in GMT.  I would like to convert this date field to the local time zone of the user in a SELECT statement.  Currently, all users are on EST, but I would like the flexibility to create this select statement so that if a user on another timezone (PST for example) runs the same query, it will return the date/time in PST.

Is this possible?  If so,how?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of sventhan
sventhan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can use the SWITCHOFFSET
here is an example from books online

CREATE TABLE dbo.test 
    (
    ColDatetimeoffset datetimeoffset
    );
GO
INSERT INTO dbo.test 
VALUES ('1998-09-20 7:45:50.71345 -5:00');
GO
SELECT SWITCHOFFSET (ColDatetimeoffset, '-08:00') 
FROM dbo.test;
GO
--Returns: 1998-09-20 04:45:50.7134500 -08:00
SELECT ColDatetimeoffset
FROM dbo.test;
--Returns: 1998-09-20 07:45:50.7134500 -05:00

Open in new window

Avatar of jbaird123
jbaird123

ASKER

Thanks!