Reference · Dates

date.days_in_month

signature
date.days_in_month(int | str, int=) -> int

What it does

How many days a month has: 28 to 31. Given a date (or a date-time) it answers for that date's month; given a year and a month as ints, for that month of that year. February is 29 in a leap year.

Examples

print(date.days_in_month("2026-02-10"), date.days_in_month("2024-02-10"))print(date.days_in_month(2026, 4), date.days_in_month(2026, 1))
output
28 2930 31

Edge cases

print(date.days_in_month("2026-10-27", 5))print(date.days_in_month("2026-02-10T12:00:00Z"))print(date.days_in_month(0, 2))
output
312829

Errors

A month outside 1 to 12, a year without a month, or a first argument that is neither an int nor a date is a runtime error, not an error value.

this one fails
print(date.days_in_month(2026, 13))
output
line 1: `date.days_in_month`: there is no month 13

Chaining

print("2026-02-10" | date.days_in_month)print(range(1, 13) | map((m) => date.days_in_month(2026, m)) | sum)
output
28365

See also

date.end_of_month, date.is_leap_year, date.start_of_month, date.of

Thread
7Useful? Like it, or add to its thread below.

Thread 0 posts

On date.days_in_month(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo