|
-
Dec 7th, 2008, 04:59 PM
#1
Thread Starter
Frenzied Member
[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?
-
Dec 7th, 2008, 05:27 PM
#2
Re: Daylight savings time
Would this sample be what you're after?
-
Dec 7th, 2008, 05:55 PM
#3
Fanatic Member
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)
-
Dec 7th, 2008, 06:30 PM
#4
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
-
Dec 7th, 2008, 06:35 PM
#5
Thread Starter
Frenzied Member
Re: Daylight savings time
 Originally Posted by RhinoBull
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.
-
Dec 7th, 2008, 06:42 PM
#6
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|