Menu

gitpiper

daysInMonth javascript Code Snippet in 2024

datebeginner

Last Updated: 14 February 2024

Gets the number of days in the given month of the specified year.

  • Use the new Date() constructor to create a date from the given year and month.
  • Set the days parameter to 0 to get the last day of the previous month, as months are zero-indexed.
  • Use Date.prototype.getDate() to return the number of days in the given month.
const daysInMonth = (year, month) => new Date(year, month, 0).getDate();
daysInMonth(2020, 12)); // 31 daysInMonth(2024, 2)); // 29

javascript snippet similar to daysInMonth For You in February 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️