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

date

Get/set date component of a date-time


Description

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

Usage

date(x)

date(x) <- value

Arguments

x

a date-time object

value

an object for which the date() function is defined

Details

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

Value

the date of x as a Date

Base compatibility

date() can be called without any arguments to return a string representing the current date-time. This provides compatiblity with base:date() which it overrides.

Examples

x <- ymd_hms("2012-03-26 23:12:13", tz = "America/New_York")
date(x)
as.Date(x) # by default as.Date assumes you want to know the date in UTC
as.Date(x, tz = "America/New_York")
date(x) <- as.Date("2000-01-02")
x

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.