JavaScript Date getDate() Method



In JavaScript, the Date.getDate() method is used to retrieve the "day of month" from a date object. This method does not accept any parameters instead; it returns the day of the month as a numeric value between 1 and 31, representing the current day according to the local time zone. If the date object is invalid, it returns NaN (Not-a-Number).

Syntax

Following is the syntax of JavaScript Date getDate() method −

getDate();

This method does not accept any parameters.

Return Value

This method returns a numeric value representing the day of the month (1-31) for the given Date object.

Example 1

In the following example, we are demonstrating the basic usage of JavaScript Date getDate() method −






Output

The above program returns the day of the month of the current date.

Example 2

In this example, we are retrieving the day of the month for a specific date "December 25, 2023" −






Output

After executing, this program returns 25 as output.

Example 3

Here, we are using the setDate() method to add 10 days to the current date −






Output

As we can see the output, 10 days has been added to the current date.

Advertisements