Solved

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

Posted on 2007-03-26
3
354 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:andieje
3 Comments
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 18797479
Try this code...........

FORM 1

Public Class frmDateTypes
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

        TextBox1.Text = BST(3, 2007)
        TextBox2.Text = BST(10, 2007)
    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 32)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "BST Start:"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 80)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(64, 24)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "BST End:"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(72, 32)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(64, 20)
        Me.TextBox1.TabIndex = 2
        Me.TextBox1.Text = "TextBox1"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(72, 80)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(64, 20)
        Me.TextBox2.TabIndex = 3
        Me.TextBox2.Text = "TextBox2"
        '
        'frmDateTypes
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(284, 144)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "frmDateTypes"
        Me.Text = "frmDateTypes"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Public Shared Function BST(ByVal Mth As Integer, ByVal Yr As Integer) As Date
        Dim dateTemp As Date = New Date(Yr, Mth, 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
End Class
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINQ - C# to VB convertion 12 56
C# Single Form 8 42
SqlServer no dupes 25 34
i have to take the screenshot of command prompt? how to do this? 1 35
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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