what_date {ds4psy} | R Documentation |
What date is it?
Description
what_date
provides a satisficing version of
Sys.Date()
that is sufficient for most purposes.
Usage
what_date(
when = NA,
rev = FALSE,
as_string = TRUE,
sep = "-",
month_form = "m",
tz = ""
)
Arguments
when |
Date(s) (as a scalar or vector).
Default: |
rev |
Boolean: Reverse date (to
Default: |
as_string |
Boolean: Return as character string?
Default: |
sep |
Character: Separator to use.
Default: |
month_form |
Character: Month format.
Default: |
tz |
Time zone.
Default: |
Details
By default, what_date
returns either
Sys.Date()
or the dates provided by when
as a character string (using current system settings and
sep
for formatting).
If as_string = FALSE
, a "Date" object is returned.
The tz
argument allows specifying time zones
(see Sys.timezone()
for current setting
and OlsonNames()
for options.)
However, tz
is merely used to represent the
dates provided to the when
argument.
Thus, there currently is no active conversion
of dates into other time zones
(see the today
function of lubridate package).
Value
A character string or object of class "Date".
See Also
what_wday()
function to obtain (week)days;
what_time()
function to obtain times;
cur_time()
function to print the current time;
cur_date()
function to print the current date;
now()
function of the lubridate package;
Sys.time()
function of base R.
Other date and time functions:
change_time()
,
change_tz()
,
cur_date()
,
cur_time()
,
days_in_month()
,
diff_dates()
,
diff_times()
,
diff_tz()
,
is_leap_year()
,
what_month()
,
what_time()
,
what_wday()
,
what_week()
,
what_year()
,
zodiac()
Examples
what_date()
what_date(sep = "/")
what_date(rev = TRUE)
what_date(rev = TRUE, sep = ".")
what_date(rev = TRUE, sep = " ", month_form = "B")
# with "POSIXct" times:
what_date(when = Sys.time())
# with time vector (of "POSIXct" objects):
ts <- c("1969-07-13 13:53 CET", "2020-12-31 23:59:59")
what_date(ts)
what_date(ts, rev = TRUE, sep = ".")
what_date(ts, rev = TRUE, month_form = "b")
# return a "Date" object:
dt <- what_date(as_string = FALSE)
class(dt)
# with time zone:
ts <- ISOdate(2020, 12, 24, c(0, 12)) # midnight and midday UTC
what_date(when = ts, tz = "Pacific/Honolulu", as_string = FALSE)