ISOWEEKNUMBER - Returning a non-existing week 53.

HikC

New Member
Joined
Jun 28, 2011
Messages
11
Hi,

What did I overlook since the ISOweeknumber function returns week 53 for the date 12/30/2019?

Code:
Public Function ISOweeknumber(Dt As Date) As Long
    ISOweeknumber = DatePart("ww", Dt, vbMonday, vbFirstFourDays)
End Function

Sub FindWeekNumber()

Dim Dt1 As Date, Dt2 As Date, Dt3 As Date
Dim We1 As Long, We2 As Long, We3 As Long

Dt1 = "12/29/2019"
Dt2 = "12/30/2019"
Dt3 = "12/31/2019"

We1 = ISOweeknumber(Dt1)    '   =52
We2 = ISOweeknumber(Dt2)    '   =53 ???
We3 = ISOweeknumber(Dt3)    '   =1

MsgBox We1 & " " & We2 & " " & We3

End Sub

Best regards
Henrik
 
The function by snb produces the correct week number with the string layout as per post number 1 for the OP who is in mm/dd/yyyy format and for me and my system is in in dd/mm/yyyy format. It is just the string in the VBA needs to be in US (mm/dd/yyyy) format as is normal in VBA.

Agree with you about being much safer to use dateserial but wanted to show the OP how to get the function to work as the OP posted...

What did I overlook since the ISOweeknumber function returns week 53 for the date 12/30/2019
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Whoa, you are right. It doesn't :eek:

DateSerial or Clng it is then. Probably ok for the OP as in mm/dd/yyyy

Thanks Steve.
 
Last edited:
Upvote 0
Its because its ambiguous. Perfectly acceptable dates in the UK and the US but they are different dates to each country. Try this #12/10/2019#
 
Upvote 0
Yep, that is better with #12/10/2019# but still prefer DateSerial :cool:

Knew the dates are ambiguous but normally VBA only accepts the US format so even more pain with dates :(
 
Last edited:
Upvote 0
I'm not sure whether I contribute to clarification or confusion ... but I still need the ISOWeeknumber function provided by Mark858 (snb).

Using DATESERIAL (i.e. DATESERIAL(2019, 12, 30)) with my original ISOWeeknumber function also returns week 53 for 12/30/2019.

/Henrik
 
Upvote 0
Sorry HikC but can't test it at the moment as only on my laptop now which is Excel 2010 which doesn't support WorksheetFunction.ISOweeknum (which was probably my issue yesterday with it).
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,840
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top