Link to home
Start Free TrialLog in
Avatar of andieje
andieje

asked on

how to find last sunday in march - help with british summer time

Hi

I have a function that works out the start and end of british summer time.It's worked on previous years but this year it doesnt work. This function says the start of BST is 1/4/2007 this year but the start of bst this year is 25/3/2007. The start of bst is always the last sunday in march.

Please can you show me how to calculate the date that is the alst sunday in march given the year or helpme modify this function i already have

thanks a lot
andrea

    Public Shared Function BSTStart(ByVal year As Integer) As Date
        ' This function returns the start date for BST, given the year
        ' Daylight savings always starts on the last Sunday of March
        ' Written 20 Sep 2004 by GG Certain
        ' Modified for BST 19 Aug 2005

        Const april As Integer = 4
        ' Set the date to April 1st
        Dim dateTemp As Date = New Date(year, april, 1)
        Dim daySpan As TimeSpan = New TimeSpan(1, 0, 0, 0, 0)
        Do While dateTemp.DayOfWeek <> DayOfWeek.Sunday
            dateTemp = dateTemp.Subtract(daySpan)
        Loop
        Return dateTemp
    End Function

    Public Shared Function BSTEnd(ByVal year As Integer) As Date
        ' This function returns the end date for BST, given the year
        ' BST always ends on the last Sunday in October
        ' Written 20 Sep 2004 by GG Certain

        Const october As Integer = 10
        ' Set the date to October 31st
        Dim dateTemp As Date = New Date(year, october, 31)
        Dim daySpan As TimeSpan = New TimeSpan(1, 0, 0, 0, 0)
        Do While dateTemp.DayOfWeek <> DayOfWeek.Sunday
            dateTemp = dateTemp.Subtract(daySpan)
        Loop
        Return dateTemp
    End Function
ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial