View source: R/time_util_fun.R
days_in_month | R Documentation |
days_in_month
computes the number of days in the months of
given dates (provided as a date or time dt
,
or number/string denoting a 4-digit year).
days_in_month(dt = Sys.Date(), ...)
dt |
Date or time (scalar or vector).
Default: |
... |
Other parameters (passed to |
The function requires dt
as "Dates",
rather than month names or numbers,
to check for leap years (in which February has 29 days).
A named (numeric) vector.
is_leap_year
to check for leap years;
diff_tz
for time zone-based time differences;
days_in_month
function of the lubridate package.
Other date and time functions:
change_time()
,
change_tz()
,
cur_date()
,
cur_time()
,
diff_dates()
,
diff_times()
,
diff_tz()
,
is_leap_year()
,
what_date()
,
what_month()
,
what_time()
,
what_wday()
,
what_week()
,
what_year()
,
zodiac()
days_in_month()
# Robustness:
days_in_month(Sys.Date()) # Date
days_in_month(Sys.time()) # POSIXct
days_in_month("2020-07-01") # string
days_in_month(20200901) # number
days_in_month(c("2020-02-10 01:02:03", "2021-02-11", "2024-02-12")) # vectors of strings
# For leap years:
ds <- as.Date("2020-02-20") + (365 * 0:4)
days_in_month(ds) # (2020/2024 are leap years)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.