Hello, this is my first post here so I hope I’m doing it right I have a problem with the DateTime library and the keyword ‘Convert Date’ regarding week numbers. When I use a date like 2024-12-30 and use Convert Date with outputformat=%#W to determine the week number, I get ‘week 53’ instead of 52. When I input the date 2025-01-12 I get ‘week 1’ instead of 2. The first week of 2025 gets converted into ‘week 0’. So every test case I run that does something after December 30 2024 fails on the week number. It seems that every date before week 52 in 2024 works correctly.
Someone mentioned this might have to do with ISO and maybe this is some kind of bug in the DateTime library? Is there any way to fix this or make it work? I could use a custom Python script using something like “return datetime.date(year, month, day).isocalendar().week” but I would like to know why this suddenly became a problem (test cases in years like 2022, 2023 and all of 2024 except the last week worked fine). Is this a (known) bug or am I doing something wrong? I have updated Robot Framework to version 7.1 but that did not fix the issue for me. Anything that helps or explains this would be helpful, thank you.
The year 2024 was a leap year (with 29th February), and so it had 53 weeks. You just need to be aware of this and adjust your code accordingly. See the detailed explanation on Wikipedia.
In my opinion, DateTime library is returning the correct week values.
Hello Hélio, thanks for your reply. I’m not sure what you’re saying is correct. Indeed, 2024 was a leap year but that gives one extra day to a year, not an extra week. The Wikipedia page mentions “These 53-week years occur on all years that have Thursday as 1 January and on leap years that start on Wednesday.” But 2024 did not start on Wednesday and 2025 did not start on Thursday, so both years should have 52 weeks according to ISO. Every calendar I have checked says 2024 had 52 weeks and week 1 started December 30 2024. So I’m still thinking this DateTime behaviour is not right? Thank you.
If the issue is real, it should happen via plain python too as DateTime library is based on python’s datetime & time modules that are shipped with python. And indeed it did, see:
So, what happens under the hood in “python” would look something like this:
Thanks rasjani! I didn’t know about the %#V option but I looked it up and used it… and it works! I have some more testing to do, but it seems this solved my problem and returns the correct week numbers.