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

daylight savings time

Status
Not open for further replies.

eaglejohn

Programmer
Mar 10, 2004
12
US
I have multiple reports that are generated around the world. My users in Japan want to convert the time stamps in our database to their time. The problem is how do i account for day light savings time. Does Crystal have any built in function to handle this?
 
I had a similar problem, but couldn't find a standard Crystal function. So I created my own custom function, and it works great for me. I'm actually converting from GMT to Central time (as well as accounting for Daylight Savings Time), so you can change the time difference constants according to the time zone you're working with. Also, this is for North America Daylight Savings Time ... don't know what the rules might be for other parts of the world. You can do a Google search to find out. Anyway, here's my function.

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)

Jerry
 
Jerry, the only problem I see in your function is that your assuming 12 am for all your calculations. In the United States, the time changes are made at 2am.

Here is the way I do it:
Code:
Function  (dateTimeVar Date_Field)

local datetimevar begin_date := datetime(year(Date_Field),1,1,2,0,0);
local datetimevar work_date := dateadd("m",3,begin_date)+7;
local datetimevar DLSStart := work_date - dayofweek(work_date) + 1;
work_date := dateadd("m",10,begin_date);
local datetimevar DLSEnd   := work_date - dayofweek(work_date) + 1; 

//currently setup for GMT to CT (5 hours difference)
local datetimevar result_date := DateAdd("h",-5,Date_Field);

//if in DLS Timeframe, subtract 1 more hour
if Date_Field in DLSStart to DLSEnd then
    result_date := DateAdd("h",-1,result_date);

result_date;

~Brian
 
Brian ... that's true, but only if you need to convert times that happen to fall between midnight and 2am on those 2 Sundays when DST begins and DST ends.

All other times during the rest of the year are converted correctly. For our applications, we never have date entries that occur then, so it's not a problem for us.

Thanks for pointing that out though, since it could be a consideration for Eaglejohn and others.

Jerry
 
Thank you all for your comments and suggestions. We just added another site to our system in Japan and they do not have DST. We are looking into using GMT time on our terminal server which also does not have DST, then we can just subtract the time difference. However, if we don't go that way i will be able to use your suggestion.

Thanks again, Eaglejohn
 
The problem with fixed formulas is that they don't automatically adjust to the time zone of the PC running the report.

Have a look at the list of 3rd-party utilities listed at: My "CUT Light" UFL includes functions for providing such adjustment where the PC's time zone as well as Day Light savings are taken into account when doing time convesrions.

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top