[RESOLVED] Calculating the first Sunday of Advent
Hello, I am trying to calculate the first Sunday of Advent in VB6 (for any future year).
Advent Sunday is the fourth Sunday before Christmas Day.
This is equivalent to the Sunday nearest to St. Andrew's Day, 30 November.
So for example St. Andrew's Day this year is day #334
Therefore this years Advent Sunday is 03/12/17 (which is day #337)
How can I find this day# automatically in VB6 for future years?
Thanks in advance ;)
*Note*: I have been playing with code of my own of to sort this.
And have just been tying myself in Knots :sick:
Re: Calculating the first Sunday of Advent
Hi Brain
this is with Dateformat Germany "dd.mm.yyyy", you will have to work
on the Format you want
Code:
Private Function GetViertenAdvent(JahrA As Long) As Date
Dim i As Long
For i = 24 To 1 Step -1
If Format$(i & ".12." & JahrA, "ddd") = "So" Then
GetViertenAdvent = Format$(i & ".12." & JahrA, "dd.mm.yyyy")
Exit For
End If
Next i
End Function
Private Sub Command2_Click()
Dim JahrA As Long
JahrA = 2017
List2.AddItem "4. Advent " & GetViertenAdvent(JahrA)
List2.AddItem "3. Advent " & DateAdd("d", -7, GetViertenAdvent(JahrA))
List2.AddItem "2. Advent" & DateAdd("d", -14, GetViertenAdvent(JahrA))
List2.AddItem "1. Advent " & DateAdd("d", -21, GetViertenAdvent(JahrA))
End Sub
regards
Chris
Re: Calculating the first Sunday of Advent
Thanks for the quick reply Chris,
Using your code as is I get this result in the ListBox...
Code:
4. Advent 00:00:00
3. Advent 23/12/1899
2. Advent 16/12/1899
1. Advent 09/12/1899
:rolleyes:
2 Attachment(s)
Re: Calculating the first Sunday of Advent
Here's my take. If it has a bug I'm sure it can easily be fixed.
Code:
Private Function AdventSunday(ByVal Christmas As Date) As Date
AdventSunday = DateAdd("ww", -4, DateAdd("d", -(Weekday(Christmas) - 1), Christmas))
End Function
Attachment 154229
1 Attachment(s)
Re: Calculating the first Sunday of Advent
Code:
Private Function AdventSunday(ByVal Christmas As Date) As Date
Dim Weeks As Integer
Weeks = IIf(Weekday(Christmas) = vbSunday, -4, -3)
AdventSunday = DateAdd("ww", Weeks, DateAdd("d", -(Weekday(Christmas) - 1), Christmas))
End Function
I had to look up "Advent" but maybe this is it?
Attachment 154233
Re: Calculating the first Sunday of Advent
Quote:
Originally Posted by
BriansBrain
Thanks for the quick reply Chris,
Using your code as is I get this result in the ListBox...
Code:
4. Advent 00:00:00
3. Advent 23/12/1899
2. Advent 16/12/1899
1. Advent 09/12/1899
:rolleyes:
how did you change the Code ?
you have to change the Dateformat
dillettante's code looks good to me
regards
Chris
Re: Calculating the first Sunday of Advent
OK Chris If I mod the Function to this it works...
Code:
Private Function GetViertenAdvent(JahrA As Long) As Date
Dim i As Long
For i = 24 To 1 Step -1
If Format(i & "/12/" & JahrA, "dddd") = "Sunday" Then
GetViertenAdvent = Format(i & "/12/" & JahrA, "dd/mm/yyyy")
Exit For
End If
Next i
End Function
I get ...
Code:
4. Advent 24/12/2017
3. Advent 17/12/2017
2. Advent 10/12/2017
1. Advent 03/12/2017
Big thanks again Chris :)
Re: Calculating the first Sunday of Advent
Thanks dilettante
Your code using your moded Function seems to work Fine :)
Thanks to everyone who Looked at this :D
Re: [RESOLVED] Calculating the first Sunday of Advent
Just another one on the pile:
Code:
Private Function FirstAdvent(ByVal Year As Long) As Date
FirstAdvent = DateSerial(Year, 12, 4 - Weekday(DateSerial(Year, 12, 24)))
End Function
Olaf
Re: [RESOLVED] Calculating the first Sunday of Advent
Quote:
Originally Posted by
Schmidt
Just another one on the pile:
Olaf
Works perfect ;)
Thanks again Olaf :wave: