Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing time difference automatically for moment in time report 1

Status
Not open for further replies.

Shawn12

Programmer
Sep 27, 2006
50
US
I am hoping someone might have a solution or idea that might help me save alot of time. I have 2 databases that we combine data from and one is in the eastern time zone while the other is in Phoenix. The proble is that Phoenix does not change time twice a year like the rest of us. Currently I have to manually change queries to adjust for this time difference so our reporting across sites is "moment in time" by adding either 2 or 3 hours to the timestamp depending on the current time status. Is there a was in SQL that I could have the query say if its daylight saving time add 3 hours and if its standard time add 2 hours? And if so would there be a way for me to query my data for say >=DATE()-1 and add 2 hours to that as well? I tried Date()-1.125 and that does not work. Any help would be greatly appreciated.
 

hi,
Code:
>=DATE()-1 + timeserial(2,0,0)  'and add 2 hours to that as well


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks much this helps with getting the data I need from the previous day...now if I can just getthe query to know whether we are in daylight savings or standard I am all set.
 
As Duane says you can write a function to do this or store the data. I would concur that storing the data is much more efficient especially in a big table. Your data table then is something like:
Code:
timePeriod startPeriod           endPeriod             hoursToAdd
DST        3/14/2010 2:00:00 AM  11/7/2010 1:59:59 AM  0.125
DST        3/13/2011 2:00:00 AM  11/6/2011 1:59:59 AM  0.125
ST         11/7/2010 2:00:00 AM  3/13/2011 1:59:59 AM  0.083333
ST         11/6/2011 2:00:00 AM  3/11/2012 1:59:59 AM  0.083333

then your query is something like
Code:
SELECT 
 tblTimes.ArizonaTime, 
 (select hoursToAdd from tblEasternConversion where tblTimes.arizonatime >= StartPeriod and arizonaTime <= endPeriod) AS hoursToAdd, 
 [ArizonaTime]+[hoursToAdd] AS EasternTime
FROM tblTimes;
 

Phoenix does not change time twice a year like the rest of us
Could you just have another timestamp column in your table that always 'points' to Phoenix's time (since it never changes)? Then you don't have to do anything (except to code time changes from summer to winter and back at your East location).

Have fun.

---- Andy
 
Thanks everyone I will give the table route a shot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top