CheckDayLightSavings Function:
Check if a passed datetime value is in Daylight Savings Time.
Description:
CheckDayLightSavings Function returns true if a passed datetime value is in Daylight Savings Time, otherwise returns false if the datetime value is in Standard Time. If the input parameter is not a valid date, the function will return False. If no Time part is passed with the string, it will assume the time is after 2 AM, so would return true on the first sunday of April, and False on the last Sunday in October.
Syntax:
bool = CheckDayLightSavings(dtDateTime)
Example:
<%
Response.write CheckDayLightSavings("23/12/2006 0:24:06") '--- returns: False
%>
ASP Source Code:
<%
Private Function CheckDayLightSavings(dtDateTime) Dim retVal, x, sTempDate '--- if the date time has the milliseconds, clean them off If InStr(1,CStr(dtDateTime),".") <> 0 Then dtDateTime = Left(dtDateTime, Len(dtDateTime) - 4) End If '--- If the passed string is a valid date, let's begin checking, otherwise just return False. If IsDate(dtDateTime) Then '--- We know what to do with any dates within these months If Month(dtDateTime) <> 10 And Month(dtDateTime) <> 4 Then Select Case Month(dtDateTime) Case 1, 2, 3, 11, 12 retVal = False Case 5, 6, 7, 8, 9 retVal = True End Select Else '--- If the month is April, let's check to see if the date is before or after '--- 2 AM on the first Sunday of the month If Month(dtDateTime) = 4 Then If Day(dtDateTime) < 8 Then For x = 1 To Day(dtDateTime) sTempDate = CStr(Month(dtDateTime)) & "/" & x & _ "/" & CStr(Year(dtDateTime)) If Weekday(sTempDate) = 1 Then If Day(sTempDate) < Day(dtDateTime) Then '--- First sunday in April has already passed, so we are now in DST retVal = True Exit For Else '--- It's the first Sunday in April! '--- Let's see if it's past 2 AM. If there is no time '--- part in dtDateTime (time part = "00:00:00"), '--- we are going to assume it's past 2 AM If (Hour(dtDateTime) >= 2) Or _ (Hour(dtDateTime) = 0 And _ Minute(dtDateTime) = 0 And _ Second(dtDateTime) = 0) Then retVal = True Exit For Else retVal = False End If End If Else retVal = False End If Next Else '--- we know what to do if the day is equal to or greater than the 8th retval = True End If '--- If the month is October, let's check to see if date is before or after '--- 2 AM on the last Sunday of the month ElseIf Month(dtDateTime) = 10 Then '--- We know what to do if the day is less than then 25th If Day(dtDateTime) < 25 Then retval = True Else For x = 25 To Day(dtDateTime) sTempDate = CStr(Month(dtDateTime)) & "/" & x & _ "/" & CStr(Year(dtDateTime)) If Weekday(sTempDate) = 1 Then If Day(sTempDate) < Day(dtDateTime) Then '--- last sunday in oct has already passed, '--- so we aren't in DST anymore retVal = False Exit For Else '--- It's the last Sunday in October! '--- Let's see if it's past 2 AM. If there is no time part '--- in dtDateTime (time part = "00:00:00"), '--- we are going to assume it's past 2 AM If (Hour(dtDateTime) >= 2) Or _ (Hour(dtDateTime) = 0 And _ Minute(dtDateTime) = 0 And _ Second(dtDateTime) = 0) Then retVal = False Exit For Else retVal = True End If End If Else retVal =True End If Next End If End If End If Else '--- if the string passed to the function is not a valid date, let's return false. retVal = False End If CheckDayLightSavings = retVal End Function
%>
|