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
Solved

Using Local Time Zone wtih SQL Server

Posted on 2011-02-23
4
331 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
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:ewangoya
ID: 34964476
0
 

Author Closing Comment

by:jbaird123
ID: 34964573
Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OPENDATASOURCE 8 41
sql calculate reminders 11 77
Table create permissions on SQL Server 2005 9 43
MS SQLK Server multi-part identifier cannot be bound 5 41
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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