Date-time must be a POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, xts, its, ti, jul, timeSeries, and fts objects.

date(x)

date(x) <- value

Arguments

x

a date-time object

value

an object for which the date() function is defined

Value

the date of x as a Date

Details

date() does not yet support years before 0 C.E. Also date() is not defined for Period objects.

Examples

x <- as.POSIXct("2012-03-26 23:12:13", tz = "Etc/GMT+8") date(x)
#> [1] "2012-03-26"
as.Date(x) # by default as.Date assumes you want to know the date in UTC
#> [1] "2012-03-27"
as.Date(x, tz = "Etc/GMT+8")
#> [1] "2012-03-26"
date(x) <- as.Date("2000-01-02") x
#> [1] "2000-01-02 23:12:13 -08"