I was working on an Excel file today in an attempt to automate most of it's requirements. One cell is required to have either PDT or PST depending upon what time of year it is. I could not find anything in VB 6 that tested the system clock to determine if the time of year was currently standard or daylight time so I wrote this:

VB Code:
  1. Sub CheckPDT()
  2.  
  3.    'Holds the date for the start and end PDT
  4.     Dim PDTStart As String
  5.     Dim PDTEnd As String
  6.    
  7.     'These hold the values days, months, year, name of the day of the week, and the number of the day of the week
  8.     Dim MyDay As String
  9.     Dim MyMonth As String
  10.     Dim MyYear As String
  11.     Dim DayNum As String
  12.     Dim TestMonth As Integer
  13.     Dim TestDay As Integer
  14.    
  15.     'The date we are going to test
  16.     Dim MyDate As String
  17.    
  18.     'Hold the difference between 2 dates
  19.     Dim DiffApril As Integer
  20.     Dim DiffOct As Integer
  21.    
  22.     'Set the initial TestMonth and TestDay for April 1
  23.     TestMonth = 4
  24.     TestDay = 1
  25.    
  26.     'Get the first Sunday in April by cycling thru the days beinning from the 1st
  27.     Do Until MyDay = "Sunday"
  28.         MyDate = CStr(TestMonth) & "/" & CStr(TestDay) & "/" & Year(Date)
  29.         MyDate = DateValue(MyDate)
  30.         DayNum = Day(MyDate)
  31.         MyMonth = Month(MyDate)
  32.         MyMonth = MonthName(MyMonth, False)
  33.         MyDay = Weekday(MyDate)
  34.         MyDay = WeekdayName(MyDay, False, 1)
  35.         If MyDay = "Sunday" Then
  36.             PDTStart = MyMonth & " " & DayNum & ", " & Year(Date)
  37.             Exit Do
  38.         End If
  39.         TestDay = TestDay + 1
  40.     Loop
  41.    
  42.     'Reset the TestMonth, TestDay  to October 31 and MyDay to nothing
  43.     TestMonth = 10
  44.     TestDay = 31
  45.     MyDay = ""
  46.    
  47.     'Get the last Sunday in October by cycling backwards thru the days beginning with the 31st
  48.     Do Until MyDay = "Sunday"
  49.         MyDate = CStr(TestMonth) & "/" & CStr(TestDay) & "/" & Year(Date)
  50.         MyDate = DateValue(MyDate)
  51.         DayNum = Day(MyDate)
  52.         MyMonth = Month(MyDate)
  53.         MyMonth = MonthName(MyMonth, False)
  54.         MyDay = Weekday(MyDate)
  55.         MyDay = WeekdayName(MyDay, False, 1)
  56.         If MyDay = "Sunday" Then
  57.             PDTEnd = MyMonth & " " & DayNum & ", " & Year(Date)
  58.             Exit Do
  59.         End If
  60.         TestDay = TestDay - 1
  61.     Loop
  62.    
  63.     'Get the difference between today's date and the start and end of Daylight Savings Time
  64.     DiffApril = Val(DateDiff("d", PDTStart, Date))
  65.     DiffOct = Val(DateDiff("d", PDTEnd, Date))
  66.    
  67.     'Display the time
  68.     If (DiffApril > 0) And (DiffOct < 0) Then
  69.         MsgBox "The time is " & Time & " Pacific Daylight Time."
  70.     Else
  71.         MsgBox "The time is " & Time & " Pacific Standard Time."
  72.     End If
  73.  
  74. End Sub