Adjusting DATETIME for Daylight Savings and Time Zone

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Adjusting DATETIME for Daylight Savings and Time Zone

Jason McNellis
Dear List,



I have a file with about 4 million records.  Each record has a datetime
column that records when that event happened in CST.   For each event, I
also have the time zone (TZ) and whether daylight saving time (DST) is
observed (linked through zip codes).   I want to convert all the datetimes
to their correct time zone (Many of the events did not occur in states
within the CST).  For example if an event happened in Maine, I want to add
one hour to the datetime.



I tried the following code:

IF (TZ = "EST") NewDateTime = CTIME.HOURS(Datetime+1) .

IF (TZ = "EST+1") NewDateTime = CTIME.HOURS(Datetime+2) .

etc.

FORMATS NewDateTime(DATETIME25).

EXECUTE .



The code above knocks off over 400 years!  I assume my CTIME function is
incorrect can anyone fix the above and/or tell me where I went wrong?

Thank you in advance.  Jason





Jason McNellis

Educator / Analyst
Reply | Threaded
Open this post in threaded view
|

Re: Adjusting DATETIME for Daylight Savings and Time Zone

Richard Ristow
At 12:48 PM 11/27/2006, Jason McNellis wrote:

>Each record [in my file] has a datetime column that records when that
>event happened in CST. [...] I want to convert all the datetimes to
>[the local time in] their correct time zone. For example if an event
>happened in Maine, I want to add one hour to the datetime.
>
>I tried the following code:
>
>IF (TZ = "EST")   NewDateTime = CTIME.HOURS(Datetime+1) .
>IF (TZ = "EST+1") NewDateTime = CTIME.HOURS(Datetime+2) .

I think you want

IF (TZ = "EST")   NewDateTime = Datetime + TIME.HMS(1).
IF (TZ = "EST+1") NewDateTime = Datetime + TIME.HMS(2).

etc.

-Good luck and best wishes,
  Richard