Skip to content

Instantly share code, notes, and snippets.

@thisisnic
Created November 23, 2018 15:22
Show Gist options
  • Save thisisnic/71d5af6ba9bc49f1e29b3c323f40f0a3 to your computer and use it in GitHub Desktop.
Save thisisnic/71d5af6ba9bc49f1e29b3c323f40f0a3 to your computer and use it in GitHub Desktop.
Another lubridate function that has saved me from writing some really janky code is rollback() which allows you to roll a date back to the last day of the previous month or first day of the month!

Code:

library(lubridate)
my_date <- ymd("2018-11-23")
rollback(my_date)

Output:

[1] "2018-10-31"

Code:

rollback(my_date, roll_to_first = TRUE)

Output:

[1] "2018-11-01"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment