Saving More Daylight!!

Thanks to a recent change, Americans will soon be getting more daylight. Yes, we will start saving daylight approximately 3 weeks earlier this year. Previously, Daylight Savings started the first Sunday in April, now it will be the second Sunday in March!

What does that mean for IT? Nothing, and a bunch. First Outlook bases DST calculations on the local operating systems settings. So, if you book a meeting at 10AM PST after March 11th, 2007, it will actually be an hour off. Why? The calendar stores it stores it in Greenwhich Mean Time (GMT). (10AM + 8hrs for GMT = 6PM). When in actuallity (because it's after DST starts), that meeting should be on the calendar for 5PM GMT. In addition, all applications that use straight CDO will have issues (like my script and Blackberry servers).

Nicely, Microsoft has provideed a web page specifically addressing these issues. (see here)

To fix my HTML Generating Script, search for these two functions Function GetDSTStartDate(llevel) and Function GetDSTEndDate(llevel) and replace it with this code:

Function GetDSTEndDate(llevel)
' In the US, Daily Savings Ends at 2AM on the First Sunday in November.
' This function is to determine the next date.
Dim DSTYear
Dim DSTDate
DSTYear = CStr(Year(Now))
DSTDate = dateadd("d",(8-weekday(cdate("11/1/"&DSTYear))),cdate("11/1/"&DSTYear & " 02:00:00"))
If now() > DSTDate then
DSTYear = CStr(Year(DateAdd("yyyy",1,Now)))
DSTDate = dateadd("d",(8-weekday(cdate("11/1/"&DSTYear))),cdate("11/1/"&DSTYear & " 02:00:00"))
End If
If llevel >0 Then GenLogFile "Daylight savings ends:" &DSTDate
GetDSTEndDate = DSTDate
End Function

Function GetDSTStartDate(llevel)
' In the US, Daily Savings starts at 2AM on the Second Sunday of March.
' This function is to determine the next date.
Dim DSTYear
Dim DSTDate
DSTYear = CStr(Year(Now))
DSTDate = dateAdd("d",7,dateadd("d",(8-weekday(cdate("3/1/"&DSTYear))),cdate("3/1/"&DSTYear & " 02:00:00")))
If now() > DSTDate then
DSTYear = CStr(Year(DateAdd("yyyy",1,Now)))
DSTDate = dateAdd("d",7,dateadd("d",(8-weekday(cdate("3/1/"&DSTYear))),cdate("3/1/"&DSTYear & " 02:00:00")))
End if
If llevel >0 Then GenLogFile "Next Daylight savings is:" &DSTDate
GetDSTStartDate = DSTDate
End Function

Hopefully, we all get to enjoy a bit more of this saved up daylight by playing outside. I declare from this date forward that 3PM is beginning of recess. Now just need to decide what time zone that's in....

Comments

Thanks for the code, but

Thanks for the code, but I've found a small problem with your code. It returns the wrong dates for several years. For example, in 2009 it adds a week to the end date. The scrpt returns 11/08/2009, when it should be 11/01/2009. The script isn't taking into account for months which begin on Sunday. I made a small change to both scripts and now they work correctly. Here are the changes:
Remove the lines:
DSTYear = CStr(Year(Now))
DSTDate = dateadd("d",(8-weekday(cdate("11/1/"&DSTYear))),cdate("11/1/"&DSTYear & " 02:00:00"))
And replace them with:
n = 8-weekday(cdate("11/1/"&DSTYear))
If n = 7 Then
'The first day of the month is Sunday
DSTDate = dateadd("d",0,cdate("11/1/"&DSTYear & " 02:00:00"))
Else
DSTDate = dateadd("d",n,cdate("11/1/"&DSTYear & " 02:00:00"))
End If

and this in the

n = 8-weekday(cdate("11/1/"&DSTYear))
If n = 7 Then
DSTDate = dateAdd("d",7,dateadd("d",0,cdate("3/1/"&DSTYear & " 02:00:00")))
Else
DSTDate = dateAdd("d",7,dateadd("d",n,cdate("3/1/"&DSTYear & " 02:00:00")))
End If

Other then that, it works FANTASTIC! THANK YOU!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <blockquote> <center> <hr> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options