JavaScript Date getDay() method - JavaScript Tutorial

JavaScript Date getDay() method

BLUF: This tutorial on JavaScript Date getDay() 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 getDay() method

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

The getDay method in JavaScript retrieves the numerical representation of the day of the week for a given date, taking into account the local time. The days are indexed starting from 0, where 0 corresponds to Sunday.

Syntax

The syntax for the getDay method is as follows:

Example

dateObj.getDay()

Return

A numerical value ranging from 0 to 6 that indicates the days of the week corresponding to the given date.

JavaScript Date getDay method example

In this section, we will explore the getDay method using a variety of examples.

Example 1

Let’s examine an illustration that demonstrates how to display the current day's weekday value.

Example

<script>

var day=new Date();

document.writeln(day.getDay());

</script>

Output:

Example 2

Let’s examine an example that demonstrates how to output the day of the week based on a specified date.

Example

<script>

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

document.writeln(day.getDay())

</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