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
Solved

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

Posted on 2007-03-26
3
355 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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