VS 2008 Check for DST on Saturday in the US

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
I think I have a function that'll throw up a messagebox if the current day is the Saturday before the Daylight Saving Time change for the US. The days it changes is the 2nd Sunday in March and the 1st Sunday in November, the time doesn't matter in this app, just the date.
VB.NET:
    Private Function CheckDST() As Boolean
        With DateTime.Today
            Select Case .Month 'Month is one based
                Case 3I 'March
                    If .DayOfWeek = DayOfWeek.Saturday AndAlso .Day >= 7I AndAlso .Day <= 13I Then
                        MessageBox.Show("Spring")
                        Return True
                    Else
                        Return False
                    End If
                Case 11I 'November
                    If .DayOfWeek = DayOfWeek.Saturday AndAlso .Day <= 6I Then 'Day is one based
                        MessageBox.Show("Fall")
                        Return True
                    Else
                        Return False
                    End If
                Case Else : Return False
            End Select
        End With
    End Function
Do I have it right?
 
I forgot to mention yesterday that I found a better solution that trying to figure out the date and crap manually, plus if the rules change then I've gotta change my program, this way eliminates that hassle:
VB.NET:
Dim daylight As Globalization.DaylightTime = TimeZone.CurrentTimeZone.GetDaylightChanges(DateTime.Today.Year)
Dim DayLightStart As DateTime = daylight.Start.AddDays(-1I)
Dim DayLightEnd As DateTime = daylight.End.AddDays(-1I)
 
For those looking to get the DayLight Saving time change day (not the Saturday beforehand like I was looking for) use this code:
VB.NET:
Dim daylight As Globalization.DaylightTime = TimeZone.CurrentTimeZone.GetDaylightChanges(DateTime.Today.Year)
Dim DayLightStart As DateTime = daylight.Start
Dim DayLightEnd As DateTime = daylight.End
It's the same code, just not subtracting a day when pulling it out of the daylight var.
 
Back
Top