Results 1 to 6 of 6

Thread: [RESOLVED] Daylight savings time

  1. #1

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Resolved [RESOLVED] Daylight savings time

    I'm adding a function to see if the current day lands during Daylight savings time.

    How do you get the dates for second Sunday in March and the first Sunday in November of the current year?

  2. #2

  3. #3
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: Daylight savings time

    Like this:


    Code:
    Dim DSTon As Date, DDSoff As Date, DOW As Integer
    
    DOW = (8 - WeekDay(DateSerial(Year(Date), 3, 1))) Mod 7
    DSTon = DateSerial(Year(Date), 3, 1 + DOW + 7)
    
    DOW = (8 - WeekDay(DateSerial(Year(Date), 11, 1))) Mod 7
    DSToff = DateSerial(Year(Date), 11, 1 + DOW)
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Daylight savings time

    Time should be considered as well:
    Code:
    Function InDST(Optional ByVal DateTime As Date, _
                   Optional ByRef dstStart As Date, _
                   Optional ByRef dstEnd As Date) As Boolean
       
       If DateTime = 0 Then DateTime = Now
       dstStart = DateSerial(Year(DateTime), 3, 1) + #2:00:00 AM#
       dstStart = dstStart + 14 - Weekday(dstStart, vbMonday) '-- 2nd Sunday in March
       dstEnd = DateSerial(Year(DateTime), 11, 1) + #2:00:00 AM#
       dstEnd = dstEnd + 7 - Weekday(dstEnd, vbMonday)  '-- 1st Sunday in November
       If (DateTime >= dstStart) Then If (DateTime < dstEnd) Then InDST = True
    
    End Function
    
    Sub TestDST()
       Dim dstStart As Date, dstEnd As Date, dt As Date
          
       Debug.Print Now, InDST()
       Debug.Print Now, InDST(, dstStart, dstEnd), dstStart, dstEnd
       dt = #3/9/2008 1:30:00 AM#
       Debug.Print dt, InDST(dt)
       dt = #3/9/2008 5:30:00 AM#
       Debug.Print dt, InDST(dt)
       dt = #3/9/2009#
       Debug.Print dt, InDST(dt, dstStart, dstEnd), dstStart, dstEnd
    End Sub
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  5. #5

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Daylight savings time

    Quote Originally Posted by RhinoBull
    Would this sample be what you're after?
    Thanks Rino, but it looks like the start of DST has been moved from the 1st sunday in march to the 2nd.
    http://aa.usno.navy.mil/faq/docs/daylight_time.php

    The VBnet code isn't getting it correctly.
    Last edited by longwolf; Dec 7th, 2008 at 06:45 PM.

  6. #6

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Daylight savings time

    Thx technorobbo, I knew there had to be a better way than a loop.

    And thank you anhn, you got it all there

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width