Last Updated : 11 Jul, 2025
The date.getMonth() method is used to fetch the month(0 to 11) from the given Date object (0 represents the first month of the year).
Syntax:DateObj.getMonth()Parameter:
Example 1: Extracting Month from a Date Object in JavaScript
The code creates a Date
object for October 15, 1996. It then uses getMonth()
to extract the month, which is zero-indexed (October corresponds to 9), and prints it to the console.
// Creating a Date Object
let DateObj = new Date('October 15, 1996 05:35:32');
// Month from above Date Object is
// Being extracted using getMonth()
let months = DateObj.getMonth();
// Printing month.
console.log(months);
Example 2: Invalid Date Input in Date getMonth() Method
Here the date of the month should lie between 1 to 31 because no date can have a month greater than 31. That is why it returns NaN i.e, Not a Number if the month in the Date object is greater than 31.
JavaScript
// Creating a Date Object
let DateObj = new Date('October 33, 1996 05:35:32');
// Month from above Date Object is being
// Extracted using getMonth()
let months = DateObj.getMonth();
// Printing month.
console.log(months);
Example 3: Providing no parameter in Date getMonth() Method
If nothing as a parameter is given, it returns the current month. It is returning 2 as March is the third month and months are zero-indexed in JavaScript.
JavaScript
// Creating a Date Object
let DateObj = new Date();
// Month from above Date Object is being
// Extracted using getMonth()
let months = DateObj.getMonth();
// Printing month.
console.log(months);
Supported Browsers:
The browsers supported by the JavaScript Date getMonth() method are listed below:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4