Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Daylight Savings Time-determining the dates when the switch occurs

Posted on 2003-12-01
4
Medium Priority
?
255 Views
Last Modified: 2010-05-01
I was wondering if there were any vb functions or tricks to finding out the day the time changes in a given year.

In my program I need to know which day the time changes so my program can adapt its routines to account for the time change in its calculations.

if someone knows a quick way to do this that would be great.

Kelly
0
Comment
Question by:unreal400
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:dancebert
ID: 9852528
For the states which use daylight savings time, it starts at midnight on the first sunday in april, and ends at midnight on the last sunday in october.

0
 
LVL 9

Expert Comment

by:dancebert
ID: 9852655
These functions return the start and end date for daylight savings time.

Private Function FirstSunApril(p_lYear As Long) As Date
               
    Dim d1stOfMonth As Date
    d1stOfMonth = CDate("4/1/" & p_lYear)
   
    Dim d1stSunday  As Date
    If Weekday(d1stOfMonth) = 1 Then
        d1stSunday = d1stOfMonth
    Else
        d1stSunday = DateAdd("d", 8 - Weekday(d1stOfMonth), d1stOfMonth)
    End If
               
    FirstSunApril = d1stSunday

End Function

Private Function LastSunOct(p_lYear As Long) As Date
               
    Dim dLastOfMonth As Date
    dLastOfMonth = CDate("10/31/" & p_lYear)
   
    Dim dLastSunday  As Date
    If Weekday(dLastOfMonth) = 1 Then
        dLastSunday = dLastOfMonth
    Else
        dLastSunday = DateAdd("d", -1 * (Weekday(dLastOfMonth) - 1), dLastOfMonth)
    End If
               
    LastSunOct = dLastSunday

End Function
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 80 total points
ID: 9852717
You use this


Replace 2003 to any year you want

Option Explicit

Private Sub Command1_Click()
Debug.Print CalcDayLightBoundary(2003, 4, 1)
Debug.Print CalcDayLightBoundary(2003, 10, 2)
End Sub
Private Function CalcDayLightBoundary(Yr As Integer, Mon As Integer, Hr As Integer) As Date
    Dim tt As Date, NumDays As Integer
   
    On Error Resume Next
    tt = DateSerial(Yr, Mon, 1) + TimeSerial(Hr, 0, 0)
    NumDays = IIf(Weekday(tt) = 1, 0, 7 - Weekday(tt) + 1)
    If (Mon = 10) Then
        NumDays = NumDays + 28
        If (NumDays > 31) Then NumDays = NumDays - 7
    End If
    CalcDayLightBoundary = DateAdd("D", NumDays, tt)
End Function
0
 
LVL 2

Author Comment

by:unreal400
ID: 9852848
Thanks EDDYKT  that was exactly what I was looking for.

Kelly
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question