Solved

Using Local Time Zone wtih SQL Server

Posted on 2011-02-23
4
327 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now