Skip to contents

Return the number of days in a month for a given year

Usage

number_of_days(date, format = "%Y-%m-%d")

Arguments

date

either a character or a Date 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.

Value

An integer corresponding to the number of days in the month for the specified year.

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