2

How do I find the week number from an arbitrary start date in R. Let's say I want my start date to be august 1st.

Mike
  • 31
  • 1
  • 7
  • Possibly helpful: https://stackoverflow.com/questions/14454476/get-the-difference-between-dates-in-terms-of-weeks-months-quarters-and-years – MrFlick Jan 21 '20 at 18:59
  • How about this: `difftime("2020-08-21", Sys.Date(), units = "weeks")`? – sm925 Jan 21 '20 at 19:01

2 Answers2

1

Using lubridate, you can do:

interval(today(), dmy("21-08-2020"))/weeks(1)

[1] 30.42857

Or from the date of interest to another date:

interval(dmy("21-08-2020"), dmy("21-09-2020"))/weeks(1)

[1] 4.428571
tmfmnk
  • 38,881
  • 4
  • 47
  • 67
0

You can use difftime for this:

difftime("2020-08-21", Sys.Date(), units = "weeks")
# Time difference of 30.45238 weeks
sm925
  • 2,648
  • 1
  • 16
  • 28