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)
Run the code above in your browser using DataLab