Languages
[Edit]
EN

JavaScript - get number of days in month

3 points
Created by:
cory
1756

In this article, we would like to show you how to get the number of days in the month in JavaScript.

Quick solution:

 

Explanation

Edit

In the above example, we use Date class constructor that applies different variants: date string, date-time string, date, and date-time components as arguments (year, month, day, hours, minutes, seconds, milliseconds). By using ...date we forward getMonthDaysCount() arguments to Date class. Months are counted from 0 to 11, days from 1 up to 31 depending on the month. Creating Date class object with 0 as the day we achieve date that indicates last day of the previous month - that trick was used to get the number of days in the month.

Related posts

Edit

Alternative titles

  1. JavaScript - check number of days in month
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - get number of days in month

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join