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
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
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
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?
Last edited by dilettante; Dec 3rd, 2017 at 11:23 AM.
how did you change the Code ?
you have to change the Dateformat
dillettante's code looks good to me
regards
Chris
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
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