Date

Date.prototype.getDay

Returns the day of the week (0-6) for the specified date according to local time

Syntax

JavaScript
date.getDay()

Return Value

An integer from 0 (Sunday) to 6 (Saturday)

Examples

Basic Usage
const date = new Date('2024-06-15');
console.log(date.getDay()); // 6 (Saturday)
Practical Example
const days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
const now = new Date();
console.log(days[now.getDay()]);
Advanced Usage
function isWeekend(date: Date) {
  const day = date.getDay();
  return day === 0 || day === 6;
}
console.log(isWeekend(new Date('2024-06-15'))); // true

Understanding Date.prototype.getDay

The Date.prototype.getDay method in JavaScript returns the day of the week (0-6) for the specified date according to local time. It belongs to the Date object and is one of the most widely used methods for working with date values in modern JavaScript and TypeScript applications.

The method signature is date.getDay(). When called, it returns an integer from 0 (sunday) to 6 (saturday). Understanding when and how to use getDay() helps you write more expressive, readable code.

Common use cases for Date.prototype.getDay include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like date-getdate, date-getmonth, date-tolocaledatestring, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Date.prototype.getDay is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Date Methods

Other methods in the Date object

Related Tools

More Date Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.