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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GMT/UTC to Central Time problem

Status
Not open for further replies.
Apr 28, 2003
38
0
0
US
I am using the function listed below to convert my date/time fields to Central Time and it works fine. The problem is that when it adjusts for DST it bases that off of the date from the PC that is running the report. I need it to look at the date value of the database field and then at that point decide how to adjust DST for that record. If I run a report for data in February it is off by one hour now becuase DST has changed since then. In one report I could have date/time records that are in DST and some that are NOT. Any ideas?

CR v9
Oracle 9


Function (DateTimeVar gmtDateTime)
//This function converts any GMT date-time to a Local date-time after
//checking whether the date is during Daylight Saving Time or not.

NumberVar i;
DateVar searchDate;
DateVar beginDST;
DateVar endDST;
NumberVar timeDiff;
DateTimeVar localDateTime;

//Find the DST begin date (which is always the first Sunday in April)
//for the year of the "gmtDateTime" argument.
For i := 1 To 30 Do
(
searchDate := Date(Year(gmtDateTime), 04, i);
If (DayOfWeek(searchDate) = 1) then Exit For
);
beginDST := searchDate;

//Find the DST end date (which is always the last Sunday in October)
//for the year of the "gmtDateTime" argument.
For i := 31 To 1 Step -1 Do
(
searchDate := Date(Year(gmtDateTime), 10, i);
If (DayOfWeek (searchDate) = 1) then Exit For
);
endDST := searchDate;

//The difference between GMT and U.S. Central time zone is 5 hours during
//DST or 6 hours if not.
If gmtDateTime in beginDST to endDST then timeDiff := 5 else timeDiff := 6;

//Now convert GMT to Local
localDateTime := DateAdd ("h", -timeDiff, gmtDateTime)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top