SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 gmt dst adjust
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tracmonali
Starting Member

16 Posts

Posted - 04/15/2012 :  15:22:00  Show Profile  Reply with Quote
Hello,

I wish to have one of my date columns to adjust with dst and utc and populate in computed columns. For ex: during dst the date col has to be pushed back to 6 hrs else 5 hrs.

set @timediff = datediff(hh, col1, getutcdate()) this col1 is from table

select col1, (computed col) col2 = case (@timediff)
case '5' then col1 date is pushed back 5 hrs
case '6' then col1 date is pushed back 6 hrs
from table
Any help appreciated?

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/15/2012 :  16:50:38  Show Profile  Reply with Quote
see


http://www.mssqltips.com/sqlservertip/1372/daylight-savings-time-functions-in-sql-server/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tracmonali
Starting Member

16 Posts

Posted - 04/15/2012 :  17:27:12  Show Profile  Reply with Quote
Thanks. but I do not wish any start date and end date of DST. All I want is col1 in my above query is logdate (that is populated using GMT) and the computed date will be wrt to DST. ALso this will be in a stored procedure. SO could I request for something simpler, which can be computed in 1 select stmt.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/15/2012 :  17:31:23  Show Profile  Reply with Quote
then what should be using is datetimeoffset

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 04/15/2012 :  17:55:29  Show Profile  Reply with Quote
DATETIMEOFFSET is not daylight savings time-aware. If you want to calculate the offset for the current time, you can use this:
SELECT DATEDIFF(hour,GETDATE(),GETUTCDATE())
In US Central Time Zone, it will return 5 hours during daylight savings time period and 6 during standard time period.

If you are trying to calculate historical data, you will need something like they have in the link that Visakh posted earlier. However, the code in there is incorrect for dates earlier than 2007. An act of Congress messed it up for dates earlier than 2007. (Yes, I realize that last sentence is stating the obvious about US Congress).
Go to Top of Page

tracmonali
Starting Member

16 Posts

Posted - 04/15/2012 :  18:42:12  Show Profile  Reply with Quote
Thanks a lot sunitabeck. your DATETIMEOFFSET and historical data information is helpful.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000