1. ## [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?

*Note*: I have been playing with code of my own of to sort this.
And have just been tying myself in Knots

2. ## 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

End Sub```
regards
Chris

3. ## 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

4. ## 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
End Function```

5. ## 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)
End Function```

6. ## Re: Calculating the first Sunday of Advent

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

how did you change the Code ?
you have to change the Dateformat

dillettante's code looks good to me

regards
Chris

7. ## 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
Big thanks again Chris

8. ## Re: Calculating the first Sunday of Advent

Thanks dilettante

Thanks to everyone who Looked at this

9. ## 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

10. ## Re: [RESOLVED] Calculating the first Sunday of Advent

Originally Posted by Schmidt
Just another one on the pile:

Olaf
Works perfect

Thanks again Olaf

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured