Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 gmt dst adjust

Author  Topic 

tracmonali
Starting Member

16 Posts

Posted - 2012-04-15 : 15:22:00
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

52326 Posts

Posted - 2012-04-15 : 16:50:38
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 - 2012-04-15 : 17:27:12
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

52326 Posts

Posted - 2012-04-15 : 17:31:23
then what should be using is datetimeoffset

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

Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-15 : 17:55:29
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 - 2012-04-15 : 18:42:12
Thanks a lot sunitabeck. your DATETIMEOFFSET and historical data information is helpful.
Go to Top of Page
   

- Advertisement -