Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

British summer & winter times

Status
Not open for further replies.

moben

IS-IT--Management
Feb 5, 2002
116
GB
I want to be able to work out the dates of time changes in March & October (last Sunday).

E.g. I want to be able to compare a date in March against the date when the times change i.e. the last Sunday in March.

Can anyone shed any light ?

Regards,

Moben.
 
See my FAQ on how to compute any holiday or other date: faq222-5185.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Hi ArtieChoke,

Thanks for your response.

I realised that the following code was sufficient:

x="31/Oct/" + current year i.e. 31/Oct/07
y=weekday(x)

Note that for the values for weekdays for sun~sat are 1~7.

The date that I require (Last Sunday in October) = x-(y-1)

What do you think ?

Regards,

Moben.

 
This works:

Code:
Dim yr As String
Dim dt As Date
yr = InputBox("Enter a year: ")
dt = CDate("10/31/" & yr)
Do Until DatePart("w", dt, FirstDayOfWeek:=vbSunday) = vbSunday
    dt = dt - 1
Loop
MsgBox "The last Sunday in October " & yr & " falls on " & dt

Note that in the DatePart function the FirstDayOfWeek argument is optional. I put it in because some countries (notably France) start their weeks on Monday, so we need to coerce the first day of the week to Sunday.

HTH

Bob
 
And when they change it next year, you'll have to redo your calculation - doh! I know my stuff is overkill for this but it'll handle anything with only a change of a parameter.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
>And when they change it next year, you'll have to redo your calculation - doh!

I have a few questions here:

1. Who are "they"?
2. What is "it"?
3. How will "they" change "it" next year?
4. Why do I have to redo my calcluation, rather than simply providing a parameter for the year?
5. Does "doh" mean "as any fool ought to have taken into account", as it generally does, or does it mean something else here?

Thanks for clarifying,

Bob
 
1. Who are "they"?
The usual suspects - gov'ment

2. What is "it"?
time changes

3. How will "they" change "it" next year?
pass a law

4. Why do I have to redo my calcluation, rather than simply providing a parameter for the year?
'cause it may not end up on the same day - last year it was the first sunday in april, this year it's the second week in march or something like that

5. Does "doh" mean "as any fool ought to have taken into account", as it generally does, or does it mean something else here?
It's what Homer Simpson says - I use it as a superlative, etc. I think it's a multi-purpose word.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
1-4. Yes, well that makes sense. Thanks for clarifying. I do believe you could leave out the Hebrew holidays, though...

5. Oh, ok, then I won't feel insulted. I wanted to check before I did, thin-skinned soul that I am. :)

Now let me say that I've seen your code before and admire it. As you say, it's overkill but covers everything. (Well, except pagan, druidic, albanian, and hindu holidays, but let's not quibble.) I don't see exactly how to use it to get, for example, the second saturday of June 2007, but I'm sure it's in there somewhere. It would even probably take less time for me to figure it out than it took for me to write the code below, but that wouldn't have been as fun.

So, I believe the following code addresses the concerns you raise, and still represents an 80% or so reduction to your code base:
Code:
Dim i As Integer
Dim yr As Integer
Dim mo As Integer
Dim dow As Integer
Dim daysinmonth As Integer
Dim whichone As String
Dim dt As Date
Dim strWhichOne As String
yr = InputBox("Enter a year: ")
mo = InputBox("Enter a month: ")
dow = InputBox("Enter a day of week as an integer (1=Sunday, etc.): ")
whichone = InputBox("Enter which of this day in the month (1-4 or L for Last): ")
Select Case mo
    Case 2
        daysinmonth = IIf(CInt(yr) Mod 4 = 0, 29, 28)
    Case 4, 6, 9, 11
        daysinmonth = 30
    Case Else
        daysinmonth = 31
End Select
dt = CDate(CStr(mo) & "/" & CStr(daysinmonth) & "/" & CStr(yr))
Do Until DatePart("w", dt, FirstDayOfWeek:=vbSunday) = dow
    dt = dt - 1
Loop
If UCase(whichone) <> "L" Then
    If Day(dt) > 28 Then
        dt = dt - 1
        Do Until DatePart("w", dt, FirstDayOfWeek:=vbSunday) = dow
            dt = dt - 1
        Loop
    End If
    For i = 1 To 4 - CInt(whichone)
        dt = dt - 1
        Do Until DatePart("w", dt, FirstDayOfWeek:=vbSunday) = dow
            dt = dt - 1
        Loop
    Next
End If
Select Case whichone
    Case "1"
        strWhichOne = "first"
    Case "2"
        strWhichOne = "second"
    Case "3"
        strWhichOne = "third"
    Case "4"
        strWhichOne = "fourth"
    Case Else
        strWhichOne = "last"
End Select
MsgBox "The " & strWhichOne & " " & Format(dt, "dddd") & " in " & Format(dt, "mmmm yyyy") & " falls on " & dt

Bob
 
You do realize the line:

daysinmonth = IIf(CInt(yr) Mod 4 = 0, 29, 28)

doesn't handle non-leap century years correctly?
 
>And when they change it next year

Here in the UK they tend not to mess about with these dates ...unlike in the US, where they clearly do it to upset Microsoft ... ;-)
 
Bob,
Glad you didn't take offense. I use doh (or d'oh, but that's too hard to type) all the time at work and everyone there knows what's it about. Guess you gotta know your audience.

So now you've given me a challenge to add all major ethnic holidays - cool! Well, maybe I'll wait on those. I added the ones I could find easily.

I've heard Australia changes their dates every year or so - that must be cr-a-zy for IT people!

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
>You do realize [etc]

Why yes. In the year 2095 I shall get right on it...

Ok, ok....
Code:
        daysinmonth = IIf(CInt(yr) Mod 4 = 0 And CInt(yr) Mod 100 <> 0 Or CInt(yr) Mod 400 = 0, 29, 28)

Good catch.

Bob
 
strongm

"Here in the UK they tend not to mess about with these dates"

that's only been in the last 10 years or so. Prior to that few people were certain what date the change was going to be made until a few weeks before. Quite a lot of diarys were printed wrong as a result.

I don't now why it is now consistent or why it was previously inconsistent but I much prefer it this way.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
>I don't now why it is now consistent

Because we finally fully synchronised with the EU in 1994

>or why it was previously inconsistent

Well, since 1981 it hasn't been really. Last Sunday in March to move to BST, Sunday following the 4th Saturday in October to move back again (which was consistent from 1972 up until 1995. The problem is that the dates were not official until specified in an Order (and there is/was provision in the applicable Summertime Act for the dates to be varied from the standard, which is why diary publishers always liked to wait for the Order to be made - just in case), and they got the Order 'wrong' for 1995, following the date for the end of BST specified by an earlier EU directive that for some reason used a 4th Sunday in October rule that applied nowhere else but the UK. And by 1997 we were using the last Sunday in October rule
 
Thanks for the explanation. Is there anything you don't know everything about? [medal]

[gray]Experience is something you don't get until just after you need it.[/gray]
 
I knew a bit about BST because I wrote a little time zone application about 10 years ago - and remembered enough to know the right keywords for Google ...
 
They say that apps developers and police detectives know a little bit about everything.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top