rollback: Roll back date to last day of previous month

Description Usage Arguments Value Examples

View source: R/ops-%m+%.r

Description

rollback changes a date to the last day of the previous month or to the first day of the month. Optionally, the new date can retain the same hour, minute, and second information.

Usage

1
rollback(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 previous 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
date <- ymd("2010-03-03")
rollback(date)

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

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

Example output

Attaching package: 'lubridate'

The following object is masked from 'package:base':

    date

[1] "2010-02-28"
[1] "2010-02-28" "2010-03-31" "2010-04-30"
[1] "2010-02-28 12:44:22 UTC"
[1] "2010-03-01 12:44:22 UTC"
[1] "2010-02-28 UTC"
[1] "2010-03-01 UTC"

lubridate documentation built on May 30, 2017, 2:10 a.m.