Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rollbackward

Roll backward or forward a date the previous, current or next month


Description

rollbackward() changes a date to the last day of the previous month or to the first day of the month. rollforward() rolls to the last day of the current month or to the first day of the next month. Optionally, the new date can retain the same hour, minute, and second information. rollback() is a synonym for rollbackward().

Usage

rollbackward(dates, roll_to_first = FALSE, preserve_hms = TRUE)

rollback(dates, roll_to_first = FALSE, preserve_hms = TRUE)

rollforward(dates, roll_to_first = FALSE, preserve_hms = TRUE)

Arguments

dates

A POSIXct, POSIXlt or Date class object.

roll_to_first

Rollback to the first day of the month instead of the last day of the month

preserve_hms

Retains the same hour, minute, and second information? If FALSE, the new date will be at 00:00:00.

Value

A date-time object of class POSIXlt, POSIXct or Date, whose day has been adjusted to the last day of the previous month, or to the first day of the month.

Examples

date <- ymd("2010-03-03")
rollbackward(date)

dates <- date + months(0:2)
rollbackward(dates)

date <- ymd_hms("2010-03-03 12:44:22")
rollbackward(date)
rollbackward(date, roll_to_first = TRUE)
rollbackward(date, preserve_hms = FALSE)
rollbackward(date, roll_to_first = TRUE, preserve_hms = FALSE)

lubridate

Make Dealing with Dates a Little Easier

v1.7.10
GPL (>= 2)
Authors
Vitalie Spinu [aut, cre], Garrett Grolemund [aut], Hadley Wickham [aut], Ian Lyttle [ctb], Imanuel Costigan [ctb], Jason Law [ctb], Doug Mitarotonda [ctb], Joseph Larmarange [ctb], Jonathan Boiser [ctb], Chel Hee Lee [ctb], Google Inc. [ctb, cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.