DateUpdate: Changes the components of a date object

Description Usage Arguments Value Examples

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

1
2
## S3 method for class 'POSIXt'
update(object, ..., simple = FALSE)

Arguments

object

a date-time object

...

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

simple

logical, passed to fit_to_timeline. If TRUE a simple fit to time line is performed and no NA are produced for invalid dates. Invalid dates are converted to meaningful dates by extrapolating the timezones.

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

1
2
3
4
5
6
date <- as.POSIXlt("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)

Example output

Attaching package: 'lubridate'

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

    date

[1] "2010-01-01 UTC"
[1] "2011-01-01 UTC"
[1] "2009-02-10 00:10:03 UTC"

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

Search within the lubridate package
Search all R packages, documentation and source code