as_date | R Documentation |
as_date()
is a generic function that converts its input to a date (Date).
There are methods for converting date-times (POSIXct), calendars, time points, and zoned-times to dates.
For converting to a date-time, see as_date_time()
.
as_date(x, ...)
## S3 method for class 'Date'
as_date(x, ...)
## S3 method for class 'POSIXt'
as_date(x, ...)
## S3 method for class 'clock_calendar'
as_date(x, ...)
## S3 method for class 'clock_time_point'
as_date(x, ...)
## S3 method for class 'clock_zoned_time'
as_date(x, ...)
x |
A vector. |
... |
These dots are for future extensions and must be empty. |
Note that clock always assumes that R's Date class is naive, so converting a POSIXct to a Date will always retain the printed year, month, and day value.
This is not a drop-in replacement for as.Date()
, as it only converts a
limited set of types to Date. For parsing characters as dates, see
date_parse()
. For converting numerics to dates, see vctrs::new_date()
or
continue to use as.Date()
.
A date with the same length as x
.
x <- date_time_parse("2019-01-01 23:02:03", "America/New_York")
# R's `as.Date.POSIXct()` method defaults to changing the printed time
# to UTC before converting, which can result in odd conversions like this:
as.Date(x)
# `as_date()` will never change the printed time before converting
as_date(x)
# Can also convert from other clock types
as_date(year_month_day(2019, 2, 5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.