Skip to content

Instantly share code, notes, and snippets.

@jpfong
Last active November 8, 2017 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpfong/0bf8d37a39cdd65890ee7d47f659d1ab to your computer and use it in GitHub Desktop.
Save jpfong/0bf8d37a39cdd65890ee7d47f659d1ab to your computer and use it in GitHub Desktop.
Get the number of days in a month
// will return the last day of the month = the number of days in a month
function daysInMonth(anyDateInMonth) {
return new Date(anyDateInMonth.getFullYear(), anyDateInMonth.getMonth() + 1, 0).getDate();
}
let dayInNovember2017 = new Date(2017, 10, 1); // 2017-11-01
console.log(daysInMonth(dayInNovember2017)); // 30 days
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment