Solved

Using Local Time Zone wtih SQL Server

Posted on 2011-02-23
4
332 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:jbaird123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 18

Accepted Solution

by:
sventhan earned 500 total points
ID: 34964442
0
 
LVL 26

Expert Comment

by:tigin44
ID: 34964455
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

0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34964476
0
 

Author Closing Comment

by:jbaird123
ID: 34964573
Thanks!
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question