JavaScript Date getDate() method

The JavaScript method getDate retrieves the day of the month for a given date, based on the local time settings.

Syntax

The syntax for the getDate method is illustrated as follows:

Example

dateObj.getDate()

Return

A numerical value ranging from 1 to 31 that indicates the day of the given date.

JavaScript Date getDate method example

In this section, we will explore the getDate method by examining several examples.

Example 1

Let's see an example to print today's date.

Example

<script>

var date=new Date();

document.writeln("Today's day: "+date.getDate());

</script>

Output:

Output

Today's day: 16

Example 2

Let's examine an example that demonstrates how to extract and display the day from a specified date.

Example

<script>

var date=new Date("August 15, 1947 20:22:10");

document.writeln(date.getDate())

</script>

Output:

Input Required

This code uses input(). Please provide values below: