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

DateTimeUpdate

Changes the components of a date object


Description

update.Date() and update.POSIXt() return a date with the specified elements updated. Elements not specified will be left unaltered. update.Date and update.POSIXt do not add the specified values to the existing date, they substitute them for the appropriate parts of the existing date.

Usage

## S3 method for class 'POSIXt'
update(
  object,
  ...,
  roll = FALSE,
  week_start = getOption("lubridate.week.start", 7),
  simple = NULL
)

Arguments

object

a date-time object

...

named arguments: years, months, ydays, wdays, mdays, days, hours, minutes, seconds, tzs (time zone component)

roll

logical. If TRUE, and the resulting date-time lands on a non-existent civil time instant (DST, 29th February, etc.) roll the date till next valid point. When FALSE, the default, produce NA for non existing date-times.

week_start

week starting day (Default is 7, Sunday). Set lubridate.week.start option to control this.

simple

logical. Deprecated. Same as roll.

Value

a date object with the requested elements updated. The object will retain its original class unless an element is updated which the original class does not support. In this case, the date returned will be a POSIXlt date object.

Examples

date <- ymd("2009-02-10")
update(date, year = 2010, month = 1, mday = 1)

update(date, year =2010, month = 13, mday = 1)

update(date, minute = 10, second = 3)

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.