Weeknumber (Week of Year)

  • Thread starter Thread starter Heinz Kammerlander
  • Start date Start date
H

Heinz Kammerlander

Is there a function to get the number of a week of a year for a given
date? (Simmilar to Weekday)?

thx, Heinz
 
There is a built in function for Weeknumber but as far as I can
remember it sometimes generates errors around the turn of the year!

For week numbers corresponding to European ISO
(Weeks Mon - Sun, First Week of Year is the first week with 4 full days)

try

Function ISOWeekNum(d1 As Date) As Integer
'Laurent Longre function
Dim Test As Long
Test = DateSerial(Year(d1), Month(d1), Day(d1))
If Test <= 0 Or Test > 401769 Then
ISOWeekNum = 0 'default error value!
Exit Function
End If

Dim d2 As Long
d2 = DateSerial(Year(d1 - Weekday(d1 - 1) + 4), 1, 3)
ISOWeekNum = Int((d1 - d2 + Weekday(d2) + 5) / 7)
End Function


Cheers,
Peter
 
Hi,


DatePart("ww", theDate)


but there is potentially a problem with the last dates of the year, they
will return 53, but that week won't have seven days, so, any stats based on
the week number have a high risk of being biased (such as the means that are
highly influenced by extreme values).



Hoping it may help,
Vanderghast, Access MVP
 
Back
Top