Daylight Savings Time dates
Author Message
Daylight Savings Time dates

HI,

Is there a "neat" way to programatically determine the beginning and
end dates for daylight savings time... for any year?

Thanks,

George

Sun, 04 Aug 2002 03:00:00 GMT
Daylight Savings Time dates
The following routine was developed in response to another post that once

I developed the following function which, if your stated conditions are
correct (I didn't feel like looking it up), returns a Date value for either
the beginning or end daylight savings time. The function takes two
arguments, the year you are interested in and a single character, "B" for
the beginning (first day) and "E" for end (last day) of daylight savings
time. Just paste this in the (General)(Declarations) section of a form or a
BAS Module if global scope is needed.

Function DST(YearIn As Variant, _
BeginEnd As String) As Date
If InStr("BE", UCase(BeginEnd)) = 0 Then
DST = 0
ElseIf UCase(Left\$(BeginEnd, 1)) = "B" Then
DST = DateAdd("d", (8 - WeekDay("4/1/" & _
CStr(YearIn))) Mod 7, "4/1/" & CStr(YearIn))
Else
DST = DateSerial(CInt(YearIn), 10, _
32 - WeekDay(DateAdd("d", -1, "11/1/" _
& CStr(YearIn))))
End If
End Function

I guess I should have mentioned, an improper Begin/End specifier returns
"12:00:00 AM" as an error indicator (because DST returns a Date value).
Also, one glitch (very minor -- I'll let you correct for it if you want),
there is one occasion when more than one character is acceptable in BeginEnd
argument, when it is "BE". However, if you enter that, DST will treat it as
"B".

Also, because DST returns a Date value, you can do date math on it, but of
course you realized that.

And finally, you are aware that not every state observes daylight savings
time and in some cases part of some states observe it whereas other parts
don't, right?

Rick

Quote:
> HI,

> Is there a "neat" way to programatically determine the beginning and
> end dates for daylight savings time... for any year?

> Thanks,

> George

Sun, 04 Aug 2002 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages