convert week/Year to date

Hello,

have data in following format

01_2023
02_2023
03_2023
04_2023
05_2023

and need to create date from this.
Tried “String to Date&Time”, there is a predefined format string “w_Y”, but selection of this gives warning “Date needs a date, but does not support a time, time zone or offset!”.

Execution of node gives then:
ERROR String to Date&Time 0:183 Execute failed: Failed to parse date in row 'Row709_Row20_Row445_Row438: Text ‘01_2022’ could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {WeekOfWeekBasedYear[WeekFields[MONDAY,4]]=1, WeekBasedYear[WeekFields[MONDAY,4]]=2022},ISO of type java.time.format.Parsed

I also wonder because convert of my strings (calendar week) to a specific date without telling first day or last day of week (or whatever) is also needed.
From error message it looks like Monday is chosen, that’s ok for me…

Tried also with Java snippet but no success.

Any help appreciated, thanks!

Regards,
ReWi

Hi @ReWi

I don’t have a one-node solution. But I think this will work
convert_week_year_to_date.knwf (19.9 KB)
Schermafdruk van 2022-05-20 08-15-25
gr. Hans

Hi @HansS ,

thanks for your reply.
But this doesn’t help.
01_2023 means cw01 of 2023

05_2023 means cw05 of 2023

So for cw01 I need a date for this week e.g. 2. Jan … 8. Jan and for cw05 it must resolve to a date between 30. Jan … 5. Feb.

ReWi

1 Like

hi @ReWi
I think you could convert the “week_year” (e.g. “01_2023”, “02_2023”,…) string to a “day-of-year_year” string, where day-of-year=first day of the week. To do that you can use this string manipulation:

string((toInt(substr($column1$,0,2))-1)*7+1)+"_"+substr($column1$,length($column1$)-4,4)

Results: “1_2023”, “8_2023”,…
Then, you can convert using the date format “D_yyyy” where D=day of year
Results 2023-01-01, 2023-01-08,…
Alternatively, if you’re ok with Mondays,

string("1_"+$column1$)

and date format=e_w_Y
Results 2023-01-02, 2023-01-09

5 Likes

thanks a lot.
The string(“1_”+$column1$) together with date format=e_w_Y does what I want.

Any explanation why w_Y alone does not work?

I guess because week_year is not a full date, it leaves the exact day undefined

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.