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: when = NA. Using as.Date(when) to convert strings into dates, and Sys.Date(), if when = NA.

rev

Boolean: Reverse date (to Default: rev = FALSE.

as_string

Boolean: Return as character string? Default: as_string = TRUE. If as_string = FALSE, a "Date" object is returned.

sep

Character: Separator to use. Default: sep = "-".

month_form

Character: Month format. Default: month_form = "m" for numeric month (01-12). Use month_form = "b" for short month name and month_form = "B" for full month name (in current locale).

tz

Time zone. Default: tz = "" (i.e., current system time zone, see Sys.timezone()). Use tz = "UTC" for Coordinated Universal Time.

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)


[Package ds4psy version 1.0.0 Index]