Skip to content

daysInMonth

Returns the number of days in the given month of the given year.

Month is 1-based (1 = January, 12 = December) to match human convention and ISO 8601 (unlike Date.getMonth() which is 0-based).

Returns NaN if the month is out of range.

Available since v2.0.0

import { daysInMonth } from '@helpers4/date';
daysInMonth(year: number, month: number): number
ParameterTypeDescription
yearnumberA full year number (e.g. 2025)
monthnumber1-based month number (1–12)

number — Number of days in that month, or NaN for invalid month

daysInMonth(2025, 1)  // => 31 (January)
daysInMonth(2025, 2)  // => 28 (February, non-leap)
daysInMonth(2024, 2)  // => 29 (February, leap)
daysInMonth(2025, 4)  // => 30 (April)

View source on GitHub