date to yyyyww format

DutchKevin

Board Regular
Joined
Apr 13, 2011
Messages
133
Office Version
  1. 365
Platform
  1. Windows
Hello All,
it's been a while since my last post. that would mean everything is working as it should be ;)

But now i face a challenge again.
I need to convert a standard date to the (european) yyyyww format.

I already have an ISOweek UDF
Code:
Public Function WeekNumberISO(InDate As Date) As Long
    Dim D As Date
    D = DateSerial(Year(InDate - Weekday(InDate - 1) + 4), 1, 3)
    WeekNumberISO = Int((InDate - D + Weekday(D) + 5) / 7)
End Function

First I tried to connect a year to this date, (with the date in E2)
Code:
=1*(YEAR(E2))&IF(LEN(WeekNumberISO(E2))=1;0;"")&WeekNumberISO(E2)

But when i checked for 31-12-2012 it returned 201201
But I would need it to return 201301. It's the last day of 2012, but according ISO it is in week 1 on 2013.

Then i thought to avoid the end of month issue with this
Code:
=1*(YEAR(EOMONTH(E2;0)-15)&IF(LEN(WeekNumberISO(E2))=1;0;"")&WeekNumberISO(E2))
But still same result.

Do any you have a hint to a structured sollution? a UDF is also welcome
Thanks already for looking
Kevin
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hello Kevin,

Try this to get correct ISO year and week

=YEAR(E2-WEEKDAY(E2;3)+3)&TEXT(weeknumberiso(E2);"00")
 
Upvote 0
Hi Barry,
This works perfectly. Very smart thinking.
You also provided me with a good sollution for the 1 digit weeknumbers.
I'll store it in my very usefull tricks folder as well :)

Thanks
Kevn
 
Upvote 0
Hello,
Can you also suggest a translation of this to a UDF? So i can use it in VBA?

Thanks Kevin
 
Upvote 0
Hello,
In a formula this works perfectly.
Can anyone suggest a translation of this to a UDF? So i can use it in VBA?

Thanks Kevin
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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