Daylight Savings Time (DST) in Southern Hemisphere (1 Viewer)

Danick

Registered User.
Local time
Today, 02:52
Joined
Sep 23, 2008
Messages
351
I am having a little difficulty getting my DST form to work for countries in the Southern Hemisphere. The complete thread originated here:
Code:
https://access-programmers.co.uk/forums/showthread.php?t=215603

I've attached a sample database that shows the issue. Basically, enter the Start and End dates for a countries DST, and the form calculates an adjusted time zone and checks the DST CheckBox. The VBA works for all countries in the Northern Hemisphere where the Start Date is earlier than the End Date in the current year but not for Southern Hemisphere countries where the DST is the other way around (ie Start Date is in Nov and the DST End Date is in Feb.)

Appreciate if anyone has any ideas as to altering the VBA to accommodate countries in the Southern Hemisphere.

Thanks
 

Attachments

  • DST Testing.accdb
    820 KB · Views: 78

Cronk

Registered User.
Local time
Today, 16:52
Joined
Jul 4, 2013
Messages
2,772
You're having problems because your start/end DSTs are text, not dates. Change your table structure.
 

Danick

Registered User.
Local time
Today, 02:52
Joined
Sep 23, 2008
Messages
351
You're having problems because your start/end DSTs are text, not dates. Change your table structure.

I've changed them to date fields, but it didn't make a difference. The problem is the calculation needs to go the other way for countries in the Southern Hemisphere. But Can't figure out how to do it...
 

Cronk

Registered User.
Local time
Today, 16:52
Joined
Jul 4, 2013
Messages
2,772
calculation needs to go the other way for countries in the Southern Hemisphere


Why? If the current date is on or after DST start and before DST end, then it is daylight saving. I can't see any difference if it is down under.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:52
Joined
Feb 28, 2001
Messages
27,179
There are three time ranges to consider. From 1-Jan-xxxx 00:00:00 to the first critical date is range 1. From first critical date to second critical date is range 2. From second critical date to 31-Dec-xxxx 23:59:59 is range 3. If you are in range 1 or 3, it is one way. If you are in range 2, it is the other way.
 

Danick

Registered User.
Local time
Today, 02:52
Joined
Sep 23, 2008
Messages
351
I think I may have figured it out. As you pointed out, it depends on the range. I modified the code to for the 2nd range. Now I just have to figure out how to fire the AfterUpdate event from a command button on the form so that I don't have to manually select each record individually in order for DST checkbox to be set (or unset). Seems to be working for now, hope I didn't break something else...

Code:
Private Sub SetDST()


    'If IsDate(Me.DSTSTART) And IsDate(Me.DSTEND) Then
    
    If Me.DSTSTART < Me.DSTEND And IsDate(Me.DSTSTART) And IsDate(Me.DSTEND) Then
        Me.ChkDST = IsDst(Me.DSTSTART, Me.DSTEND)
        Else
        
    If Me.DSTSTART > Me.DSTEND And IsDate(Me.DSTSTART) And IsDate(Me.DSTEND) Then
    Me.ChkDST = IsDst2(Me.DSTSTART, Me.DSTEND)
     
    Else
        Me.ChkDST = False
    End If
End If
End Sub

Private Function IsDst(d1 As Date, d2 As Date) As Boolean
    IsDst = d1 < Now And Now < d2
End Function

Private Function IsDst2(d1 As Date, d2 As Date) As Boolean
'This new function is to calculate DST in southern hemisphere
    IsDst2 = d1 < Now And Now > d2
End Function
 

Cronk

Registered User.
Local time
Today, 16:52
Joined
Jul 4, 2013
Messages
2,772
Um, what is the difference between functions IsDST and IsDST2?
Also, with ranges it's always good practice to check the extremities. That is, what is the result supposed to be when today is DSStart or DSEnd?
 

Danick

Registered User.
Local time
Today, 02:52
Joined
Sep 23, 2008
Messages
351
IsDST is used to set DST for countries in Northern Hemisphere, and IsDST2 is used to set DST in Southern Hemisphere.

The problem I'm having right now is trying to loop a calculated event through the continuous form.

I can create a "GotFocus" event on the DSTEND field so that the DST can be re-calculated by simply clicking on that field. It also has an After Update event in both DSTSTART and DSTEND to set the checkbox. But rather than having the user click on each record one-by-one, I'm trying to create a command button that will loop through the records to update the DST automatically.

I've tried to create an Update Query, but the query is too complicated.
Any help appreciated...
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 01:52
Joined
Feb 28, 2001
Messages
27,179
Actually, you always can do it with one test. Either your NOW() is between the two critical dates, or it is not.

Code:
bFlag = ( date1 <= Now() ) AND ( Now() < date2 )

I understand that the flag changes meaning between hemispheres, but there will be no reversal issues for the comparison. Only for the result.

I understand that Summer north of the equator means Winter south of the equator so the sense of the flag depends on northern or southern latitudes. But for any time zone, the same test will work correctly if your date1 is earlier than date2 but both are in the same year - as long as you remember to flip the flag based on location.
 

Cronk

Registered User.
Local time
Today, 16:52
Joined
Jul 4, 2013
Messages
2,772
Re #8.

IsDST is used to set DST for countries in Northern Hemisphere, and IsDST2 is used to set DST in Southern Hemisphere.


Listen to the broken record. Look at the code. What is the difference between the two functions? Either could be used for the northern or southern hemispheres.


If DST starts on X and finishes on Y, then a date between X and Y, then a date between X and Y is DST, regardless of north/south hemisphere. If is not between X and Y, then it is not DST, regardless of north/south hemisphere.


Another issue not so far addressed. Initially your date (in text) was mm/dd. This will normally change year to year.
 

Users who are viewing this thread

Top Bottom