Days in a Month

Given separate integers month and year, return the number of days in that month in the proleptic Gregorian calendar. February has 29 days when the year is…

Given separate integers month and year, return the number of days in that month in the proleptic Gregorian calendar. February has 29 days when the year is divisible by 400, or divisible by 4 but not 100; otherwise it has 28. April, June, September and November have 30; all other months have 31.

1 <= month <= 12 and 1 <= year <= 9999. Both are exact integers. Return an integer 28, 29, 30 or 31. No locale, timezone or historical calendar cutover is applied.

Example 1: input month = 2, year = 2024; output 29. A non-century year divisible by 4 is a leap year.

Example 2: input month = 2, year = 1900; output 28. A century year not divisible by 400 is common.

Example 3: input month = 4, year = 2025; output 30. April is a 30-day month; no leap-year test is needed.

Category: Math & Numbers. Topic: math. Difficulty: Easy. Patterns: math.