Last active
November 8, 2017 21:40
-
-
Save jpfong/0bf8d37a39cdd65890ee7d47f659d1ab to your computer and use it in GitHub Desktop.
Get the number of days in a month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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