Time.org.uk
Login   Search
Skip Navigation Links
Home
My Event Countdown
SNTP Service
Daylight Saving Time
Comments
Contact
Events
Links
Games
Poetry
Firewall
XP SNTP
Scroll up
Scroll down
BST GMT Code Page 1
BST GMT Code Page 2
Scroll up
Scroll down
Bejeweled
Backgammon
Scroll up
Scroll down

Events

  • BST ends - GMT Starts (clocks go back one hour)
  • Update on Leap Second
Skip Navigation Links>Daylight Saving Time>BST GMT Code Page 2
Working with daylight saving time. (examples in VBscript)


On the previous page we looked at how to find out if a given date and time were within the BST or GMT periods.

We will now extend on that to determine which period is next and when the change will occur.

To determine the start date and time of each period we use the following two functions...

Public Function NextBST(ByVal TheDateAndTime As String) As String
    If DateDiff("s", TheDateAndTime, _
    BSTstarts(Year(TheDateAndTime))) < 1 Then
        NextBST = BSTstarts(Year(TheDateAndTime) + 1)
    Else
        NextBST = BSTstarts(Year(TheDateAndTime))
    End If
End Function

Public Function NextGMT(ByVal TheDateAndTime As String) As String
    If DateDiff("s", TheDateAndTime, _
    GMTstarts(Year(TheDateAndTime))) < 1 Then
        NextGMT = GMTstarts(Year(TheDateAndTime) + 1)
    Else
        NextGMT = GMTstarts(Year(TheDateAndTime))
    End If
End Function

...each function first determines if the date and time passed to it are beyond the start date and time of the respective period.

If your date and time is before the start date and time for your year then the result for your year is returned otherwise the result for the following year is returned.

Using the functions described so far we can calculate when the next start of the appropriate period is...

Public NextPeriod, StartDate, MyDateAndTime As String

MyDateAndTime = "12 October 2007 15:30:00"
'or
MyDateAndTime = Now()

'Avoid using Now() within your code as it is possible for it to
'cause paradoxical results if the computer time changes from one
'zone to another before all code has completed.

If IsGMT(MyDateAndTime) Then
    'It is within GMT so we want the next BST start date
    NextPeriod = "BST"
    StartDate = NextBST(MyDateAndTime)
Else
    'It is within BST so we want the next GMT start date
    NextPeriod = "GMT"
    StartDate = NextGMT(MyDateAndTime)
End If

...at this point you have now stored the name of the next period, and when it starts.

Using the code on these two pages you can now determine how long it is to the next clock change.

Go to Page 1

© 2008 TIME.org.uk