JavaScript Date getDate() Method

JavaScript Date getDate() method returns the day of the month for this date according to local time.

Syntax

getDate()

Parameters

This method does not take any parameters.

Return value

The getDate() method returns an integer between 1 and 31, representing the day of the month for the given date according to local time.

Example 1: Usage of getDate() Method

let today = new Date();
let dayOfMonth = today.getDate();

console.log("Today's date is:", dayOfMonth);

Output

Today's date is: 18

Example 2: Returning NaN

let dateobj = new Date("September 32, 1993 05:35:32");

let data = dateobj.getDate();

console.log(data);

Output

NaN

Example 3: Returning 1

In JavaScript, the Date object’s getDate() method does not default to returning 1 if the month’s date is not given. Instead, the getDate() method always returns the day of the month for the Date object on which it’s called.

let date2 = new Date(2023, 7);

console.log(date2.getDate());

Output

1

That’s it!

Related posts

JavaScript Date setDate()

JavaScript Date getDay()