JavaScript Date getDate() method - JavaScript Tutorial

JavaScript Date getDate() method

BLUF: This tutorial on JavaScript Date getDate() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Date getDate() method

Understanding JavaScript Date getDate() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

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:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience