0

I come across the following issue and can fix it with a simple "-1" to the weeknumber. But would that fix work for any date and where does it come from?

date <- "2020-06-15 16:00:00"
week <- as.character(strftime(date, format = "%V"))
as.POSIXct(as.Date(paste(2020, week, 1, sep="-"), "%Y-%U-%u"))

[1] "2020-06-22 02:00:00 CEST"

We're off by a week. Thank you!

  • Can you please give more detail explaining what you're doing and how you know the answer is wrong? (Most people are not intimately with the details of the `%V`, `%U`, `%u` codes, and it's nice to save them from the trouble of looking them up ...) – Ben Bolker Jun 15 '20 at 18:04
  • Please check this nice answer by @Uwe, where he makes a smooth path through the week jungle: [Transform year/week to date object](https://stackoverflow.com/questions/45549449/transform-year-week-to-date-object/45587644#45587644) (dupe-oid) – Henrik Jun 15 '20 at 18:23

0 Answers0