Search code examples
rdate

Get year corresponding to week number when week starts in prior year


I'm trying to format dates (e.g. 2024-12-30) as year and weeknumber (e.g. 2025-01).

I have tried strftime(... , "%Y-%V"), but that gives me the wrong year for some weeks, e.g.:

strftime("2024-12-30", "%Y-%V")
[1] "2024-01"  # should be 2025-01, as December 30 is in the first week of 2025

How do I get the correct year for a weeknumber from a date?


Solution

  • Looking at the documentation for strftime, the answer is:

    strftime("2024-12-30", "%G-%V")
    [1] "2025-01"