- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get a number of days in a specified month using JavaScript?
To get numbers of days in a month, use the getDate() method and get the days.
Example
You can try to run the following code to get a number of days in a month −
<!DOCTYPE html> <html> <body> <script> var days = function(month,year) { return new Date(year, month, 0).getDate(); }; document.write("Days in July: "+days(7, 2012)); // July month document.write("<br>Days in September: "+days(9, 2012)); // September Month </script> </body> </html>
Output
Days in July: 31 Days in September: 30
Advertisements