How to get week ending next Sunday from date
1 answer
I think it might be a bug with ceiling_date
as pointed out here: https://github.com/tidyverse/lubridate/issues/479
One workaround might be to grab the year / week and then round up to Sunday:
as.Date(paste0(year('2017-06-16'), week('2017-06-16') + ifelse(wday('2017-06-16')==1,0,1), 7), format = "%Y%U%u")
#[1] "2017-06-18"
From ?strptime
:
-
%Y
- year with century (i.e. 2017). -
%U
is the week of the year as decimal -
%U
- day of the week from 1-7 (1 - Monday)
So we need to shift our week by 1
(hence +1
) and then we will set the day to Sunday 7
.
0
source to share