as.POSIXct does not get format correctly

Viewed 49

I want to get hour 17 of the certain weekday (Sunday for example) of the week. So my try is

as.POSIXct(format(Sys.time(), '%U Sunday 17'), format = '%U %A %H')

which gives 2016-03-18 17:00:00 (Friday). It must be something trivial that I miss.

Update. This question is about a function producing unexpected result rather than about calculation method. So to my mind it is not a duplicate. And the trivial thing that I missed was year specification in format. So the correct answer is as.POSIXct(format(Sys.time(), '%Y %U Sunday 17'), format = '%Y %U %A %H').

0 Answers
Related