Dev Helpers

JavaScript / Dates and time

Get the last day of a month

Dev Helpers · November 5, 2026

Day zero of the following month falls on the final day of the requested month. Date handles the year rollover for December.

Worked example

console.log(new Date(Date.UTC(2026, 2, 0)).getUTCDate());

Result

28

Implementation notes

The Date constructor interprets numeric month indexes from zero. Mixing the human-facing month number with that representation is a common source of one-month errors.

Try it yourself

Run the calculation for February in a leap year and a common year.

Open the JavaScript example →

Editorial date November 5, 2026 · Published December 6, 2026

Related articles

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.