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


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

Posted on 2007-03-26
Medium Priority
Last Modified: 2012-05-05

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

    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)
        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)
        Return dateTemp
    End Function
Question by:andieje
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
LVL 27

Accepted Solution

planocz earned 2000 total points
ID: 18797479
Try this code...........


Public Class frmDateTypes
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        '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
            End If
        End If
    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.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:"
        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:"
        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"
        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"
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(284, 144)
        Me.Name = "frmDateTypes"
        Me.Text = "frmDateTypes"

    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)
        Return dateTemp
    End Function
End Class

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

610 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