Skip to content
Prev 387228 / 398502 Next

strptime, date and conversion of week number into POSIX

Sorry to answer to myself, but the format was clearly incorrect in the 
previous post. It should read, refering to the 1th day of the week:

strptime(paste0(mydate,"-1"),format="%Y-%W-%u")

It converts better, but with a NA on week 53
[1] "2020-01-06 CET"  "2020-01-13 CET"  "2020-01-20 CET"  "2020-01-27 CET"
  [5] "2020-02-03 CET"  "2020-02-10 CET"  "2020-02-17 CET"  "2020-02-24 CET"
  [9] "2020-03-02 CET"  "2020-03-09 CET"  "2020-03-16 CET"  "2020-03-23 CET"
[13] "2020-03-30 CEST" "2020-04-06 CEST" "2020-04-13 CEST" "2020-04-20 CEST"
[17] "2020-04-27 CEST" "2020-05-04 CEST" "2020-05-11 CEST" "2020-05-18 CEST"
[21] "2020-05-25 CEST" "2020-06-01 CEST" "2020-06-08 CEST" "2020-06-15 CEST"
[25] "2020-06-22 CEST" "2020-06-29 CEST" "2020-07-06 CEST" "2020-07-13 CEST"
[29] "2020-07-20 CEST" "2020-07-27 CEST" "2020-08-03 CEST" "2020-08-10 CEST"
[33] "2020-08-17 CEST" "2020-08-24 CEST" "2020-08-31 CEST" "2020-09-07 CEST"
[37] "2020-09-14 CEST" "2020-09-21 CEST" "2020-09-28 CEST" "2020-10-05 CEST"
[41] "2020-10-12 CEST" "2020-10-19 CEST" "2020-10-26 CET"  "2020-11-02 CET"
[45] "2020-11-09 CET"  "2020-11-16 CET"  "2020-11-23 CET"  "2020-11-30 CET"
[49] "2020-12-07 CET"  "2020-12-14 CET"  "2020-12-21 CET"  "2020-12-28 CET"
[53] NA                "2021-01-04 CET"  "2021-01-11 CET"  "2021-01-18 CET"
[57] "2021-01-25 CET"  "2021-02-01 CET"  "2021-02-08 CET"
Warning message:
In strptime(paste0(pays$year_week, "-1"), format = "%Y-%W-%u") :
   (0-based) yday 369 in year 2020 is invalid


Any idea on how to handle this ?




Le 22/02/2021 ? 15:26, Patrick Giraudoux a ?crit?: