lubridate (version 1.5.6)

as_date: Convert an object to a Date

Description

A drop in replacement for base as.Date with two two differences. First, it ignores timezone attribute resulting in a more intuitive conversion (see examples). Second, it does not require origin argument which defaults to 1970-01-01.

Usage

as_date(x, ...)
"as_date"(x, tz = NULL)
"as_date"(x, origin = lubridate::origin)

Arguments

x
a vector of POSIXt, numeric or character objects
...
further arguments to be passed to specific methods (see above).
tz
a time zone name (default: time zone of the POSIXt object x). See olson_time_zones.
origin
a Date object, or something which can be coerced by as.Date(origin, ...) to such an object (default: the Unix epoch of "1970-01-01"). Note that in this instance, x is assumed to reflect the number of days since origin at "UTC".

Value

a vector of Date objects corresponding to x.

Examples

Run this code
dt_utc <- ymd_hms("2010-08-03 00:50:50")
dt_europe <- ymd_hms("2010-08-03 00:50:50", tz="Europe/London")
c(as_date(dt_utc), as.Date(dt_utc))
## [1] "2010-08-03" "2010-08-03"
c(as_date(dt_europe), as.Date(dt_europe))
## [1] "2010-08-03" "2010-08-02"
## need not suply origin
as_date(10)
## [1] "1970-01-11"

Run the code above in your browser using DataCamp Workspace