'**************************************
' Name: Get WeekNumber from weeks starting on Sunday
' Description:This function calculates the weeknumber of a date for weeks starting on a sunday. The Microsoft function WeekNumber(ww, date) calculates weeknumbers for weeks starting on a Monday!
'
' Inputs:dDatum = the date to Calculate with
'
' Returns:It returns the weeknumber from the given date.
'
'Side Effects:It is only for weeks starting on a sunday!
'This code is copyrighted and has limited warranties.
'**************************************
Public Function Sunday_WeekNR(ByVal dDatum As Date) As Integer
Dim Weeknr As Integer
Dim beginDate As Date
Dim EndDate As Date
'NL: Bereken de zondag van de opgegeven week(datum)
'ENG: Calculate sunday from given week(date)
Do While Weekday(dDatum) <> vbSunday
dDatum = DateAdd("d", -1, dDatum)
Loop
beginDate = DateSerial(Year(dDatum), 1, 1)
EndDate = DateSerial(Year(dDatum), 12, 31)
'NL: Bereken start week
'ENG: Calculate start week from year
If Weekday(beginDate) <= 5 Then
Weeknr = 1
Else
Weeknr = 53
End If
'NL: Zet de startdag van de Beginweek op zondag
'ENG: Set Startday of beginweek on sunday
Do While Weekday(beginDate) <> vbSunday
beginDate = DateAdd("d", -1, beginDate)
Loop
If beginDate < DateSerial(Year(dDatum), Month(dDatum), Day(dDatum)) Then
Do
If Convert(Weekday(beginDate)) = 7 Then
If Weeknr = 54 Then
Weeknr = 1
End If
Weeknr = Weeknr + 1
If Weeknr > 52 And (Weekday(EndDate) < 5) Then
Weeknr = 1
End If
End If
'beginDate = DateAdd("d", 1, beginDate)
beginDate = DateAdd("d", 7, beginDate)
Loop Until (beginDate >= DateSerial(Year(dDatum), Month(dDatum), Day(dDatum)))
End If
If Weeknr = 54 Then
Weeknr = 1
End If
Sunday_WeekNR = Weeknr
End Function
Public Function Convert(x)
Select Case x
Case 1
Convert = 7
Case Else
Convert = x - 1
End Select
End Function
Greetz From,
** RayDance **
Hi..di..hi..di..ho, it's just a programmers Role
' Name: Get WeekNumber from weeks starting on Sunday
' Description:This function calculates the weeknumber of a date for weeks starting on a sunday. The Microsoft function WeekNumber(ww, date) calculates weeknumbers for weeks starting on a Monday!
'
' Inputs:dDatum = the date to Calculate with
'
' Returns:It returns the weeknumber from the given date.
'
'Side Effects:It is only for weeks starting on a sunday!
'This code is copyrighted and has limited warranties.
'**************************************
Public Function Sunday_WeekNR(ByVal dDatum As Date) As Integer
Dim Weeknr As Integer
Dim beginDate As Date
Dim EndDate As Date
'NL: Bereken de zondag van de opgegeven week(datum)
'ENG: Calculate sunday from given week(date)
Do While Weekday(dDatum) <> vbSunday
dDatum = DateAdd("d", -1, dDatum)
Loop
beginDate = DateSerial(Year(dDatum), 1, 1)
EndDate = DateSerial(Year(dDatum), 12, 31)
'NL: Bereken start week
'ENG: Calculate start week from year
If Weekday(beginDate) <= 5 Then
Weeknr = 1
Else
Weeknr = 53
End If
'NL: Zet de startdag van de Beginweek op zondag
'ENG: Set Startday of beginweek on sunday
Do While Weekday(beginDate) <> vbSunday
beginDate = DateAdd("d", -1, beginDate)
Loop
If beginDate < DateSerial(Year(dDatum), Month(dDatum), Day(dDatum)) Then
Do
If Convert(Weekday(beginDate)) = 7 Then
If Weeknr = 54 Then
Weeknr = 1
End If
Weeknr = Weeknr + 1
If Weeknr > 52 And (Weekday(EndDate) < 5) Then
Weeknr = 1
End If
End If
'beginDate = DateAdd("d", 1, beginDate)
beginDate = DateAdd("d", 7, beginDate)
Loop Until (beginDate >= DateSerial(Year(dDatum), Month(dDatum), Day(dDatum)))
End If
If Weeknr = 54 Then
Weeknr = 1
End If
Sunday_WeekNR = Weeknr
End Function
Public Function Convert(x)
Select Case x
Case 1
Convert = 7
Case Else
Convert = x - 1
End Select
End Function
Greetz From,
** RayDance **
Hi..di..hi..di..ho, it's just a programmers Role