Return the number of days in a month for a given year
Arguments
- date
either a
character
or aDate
of length 1. See examples below.- format
a
character
of length 1. Used to specify the format of the date. Default is"%Y-%m-%d"
(i.e. 2024-12-25). See examples below.
Examples
## Default ----
number_of_days("2024-02-01")
#> [1] 29
## Day doesn't matter ----
number_of_days("2024-02-23")
#> [1] 29
## Year matters ----
number_of_days("2023-02-23")
#> [1] 28
## Change the format ----
number_of_days("2024/02/23", format = "%Y/%m/%d")
#> [1] 29
## French format ----
number_of_days("23/02/2024", format = "%d/%m/%Y")
#> [1] 29