JavaScript Date getDay() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Day of week

What You’ll Learn

getDay() returns the day of the week as an integer from 0 (Sunday) to 6 (Saturday) in local time. This guide covers syntax, five examples, weekday name helpers, comparisons with similar methods, and real scheduling patterns.

01

Syntax

date.getDay()

02

Range

0 – 6

03

Sunday = 0

US-style index

04

vs getDate

Week vs month

05

Name map

Helper array

06

Validate

Invalid → NaN

Introduction

Scheduling apps, store hours, and “Happy Friday” banners all need to know which weekday a Date falls on. The getDay() method extracts that weekday as a small integer using the user’s local timezone.

If you need the calendar date number instead (1–31), use getDate(). For UTC weekday logic, see getUTCDay().

Understanding the getDay() Method

Date.prototype.getDay() is a zero-argument instance method. It never mutates the original Date—it only reads the weekday component according to local time rules.

The return value is a number, not a string. Most apps map that number to a label (“Monday”) with a helper function or with toLocaleDateString({ weekday: "long" }) for locale-aware output.

💡
Beginner Tip

Memory hook: getDay = day of the week (Tuesday / 2). getDate = date number on the calendar (26th).

📝 Syntax

JavaScript
dateObj.getDay()

Parameters

  • None.

Return value

  • Integer 0–6 for a valid date in local time (0 = Sunday, 6 = Saturday).
  • NaN if dateObj is an invalid Date.

Weekday index table

  • 0 — Sunday
  • 1 — Monday
  • 2 — Tuesday
  • 3 — Wednesday
  • 4 — Thursday
  • 5 — Friday
  • 6 — Saturday

⚡ Quick Reference

GoalCode
Today’s weekday indexnew Date().getDay()
Weekday from fixed datenew Date(2024, 1, 26).getDay() → 1 (Monday)
Weekday name (locale)date.toLocaleDateString("en-US", { weekday: "long" })
Is weekend?const d = date.getDay(); d === 0 || d === 6
UTC weekdaydate.getUTCDay()
Valid date check!Number.isNaN(date.getTime())

📋 getDay() vs Similar Methods

These names look alike but answer different questions. Pick the getter that matches your UI or calculation.

getDay()
0–6

Weekday index

getDate()
1–31

Day of month

getUTCDay()
UTC weekday

Timezone-safe read

toLocaleDateString
"Tuesday"

Localized name

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Fixed dates use new Date(year, monthIndex, day) to avoid string parsing surprises.

📚 Getting Started

Read the weekday index from a known calendar date.

Example 1 — Get the Weekday Index from a Fixed Date

February 26, 2024 falls on a Monday in local time—getDay() returns 1.

JavaScript
const feb26 = new Date(2024, 1, 26);
const dayOfWeek = feb26.getDay();

console.log(dayOfWeek); // 1 (Monday)
Try It Yourself

How It Works

The constructor uses zero-based months (1 = February). getDay() ignores hours and minutes—only the calendar date in local time matters for this getter.

📈 Practical Patterns

Name mapping, validation, dynamic content, and scheduling.

Example 2 — Map the Index to a Weekday Name

Turn the numeric result into a readable English label with a small helper.

JavaScript
const WEEKDAYS = [
  "Sunday", "Monday", "Tuesday", "Wednesday",
  "Thursday", "Friday", "Saturday"
];

function getDayName(dayIndex) {
  return WEEKDAYS[dayIndex];
}

const today = new Date(2024, 1, 26);
console.log("Today is a " + getDayName(today.getDay()) + ".");
// Today is a Monday.
Try It Yourself

How It Works

Array index aligns with getDay()—index 0 is Sunday. For production i18n, prefer Intl.DateTimeFormat or toLocaleDateString instead of hard-coded English names.

Example 3 — Validate Before Calling getDay()

Guard against invalid Date objects that yield NaN.

JavaScript
function safeGetDay(date) {
  if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
    return null;
  }
  return date.getDay();
}

console.log(safeGetDay(new Date()));              // e.g. 5
console.log(safeGetDay(new Date("not-a-date")));  // null
Try It Yourself

How It Works

getTime() returns NaN on invalid dates. Checking first prevents WEEKDAYS[NaN] from silently returning undefined in UI code.

Example 4 — Dynamic Content Based on the Weekday

Show a different greeting on Monday and Friday.

JavaScript
function welcomeMessage() {
  const dayOfWeek = new Date().getDay();

  if (dayOfWeek === 1 || dayOfWeek === 5) {
    return "Happy coding day!";
  }
  return "Enjoy your day!";
}

console.log(welcomeMessage());
Try It Yourself

How It Works

1 is Monday and 5 is Friday in the ECMAScript weekday table. Your output changes when you run this on different days of the week.

Example 5 — Schedule Meetings on Specific Weekdays

Run an action only on Tuesday (2) or Thursday (4).

JavaScript
function scheduleMeeting() {
  const dayOfWeek = new Date().getDay();

  if (dayOfWeek === 2 || dayOfWeek === 4) {
    console.log("Meeting scheduled for today!");
  } else {
    console.log("No meeting today.");
  }
}

scheduleMeeting();
Try It Yourself

How It Works

This pattern powers recurring reminders, cron-like UI rules, and “open on weekdays only” checks. Combine with stored timezone data when users span multiple regions.

🚀 Common Use Cases

  • Store hours — open/closed banners based on weekday.
  • Weekend pricing — different rates when getDay() is 0 or 6.
  • Recurring events — “every Tuesday” meeting logic.
  • Dashboard labels — “Happy Friday” when index is 5.
  • Form validation — disallow submissions on Sundays.
  • Analytics buckets — group traffic by weekday index.

🧠 How getDay() Resolves the Weekday

1

Internal instant

The Date stores milliseconds since Unix epoch (UTC).

Storage
2

Local conversion

Engine applies the runtime timezone offset.

TZ
3

Extract weekday

Day-of-week index 0–6 is returned (Sunday = 0).

getDay
4

Use in logic

Compare, map to names, or branch on weekend vs weekday rules.

📝 Notes

  • getDay() is local; use getUTCDay() when you standardize on UTC.
  • Do not confuse with getDate() (day-of-month 1–31).
  • Invalid dates propagate NaN—validate first.
  • Sunday is 0 by spec; some locales start weeks on Monday in UI only.
  • For display strings, prefer locale formatters over hard-coded English arrays.
  • Near midnight, local weekday can differ from UTC weekday on the same instant.

Browser & Runtime Support

Date.prototype.getDay() has been available since the first JavaScript Date implementation (ES1). It works in every browser and Node.js.

Baseline · ES1

Date.prototype.getDay()

Supported in Chrome, Firefox, Safari, Edge, Internet Explorer, and all Node.js versions. No polyfill required.

99% Universal API
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Date.getDay() Excellent

Bottom line: Safe everywhere. Watch timezone boundaries when pairing with UTC getters or ISO strings parsed from servers.

Conclusion

getDay() is the straightforward way to read the weekday index from a JavaScript Date in local time. Map the number to a name, distinguish it from getDate(), and branch on 0–6 for scheduling and UI rules.

Next, learn getFullYear() for the four-digit year, or getUTCDay() for UTC weekday logic.

💡 Best Practices

✅ Do

  • Validate dates before calling getDay()
  • Use a helper or Intl to show weekday names
  • Pick UTC getters when storing UTC midnight
  • Document that Sunday = 0 for teammates
  • Test edge cases around local midnight

❌ Don’t

  • Confuse getDay with getDate
  • Assume index 1 means Sunday
  • Ignore NaN from bad parses
  • Hard-code English names in multilingual apps
  • Mix UTC ISO strings with local getters blindly

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.getDay()

Your foundation for weekday logic in JavaScript.

5
Core concepts
🔢 02

0–6

Sun = 0.

Range
🌐 03

Local

Not UTC.

Timezone
🔄 04

Name map

Array helper.

Display
05

Not getDate

Week vs date.

Pitfall

❓ Frequently Asked Questions

An integer from 0 to 6 representing the day of the week in the Date object's local timezone. 0 is Sunday, 1 is Monday, … 6 is Saturday. It does not return a name string.
getDay() returns the weekday index (0–6). getDate() returns the day of the month (1–31). The similar names confuse beginners—remember Day = weekday, Date = calendar date number.
getDay() uses local timezone rules. getUTCDay() reads the UTC weekday. Near midnight or across timezones they can differ by one day.
Historical convention in ECMAScript follows US-style calendars where Sunday is index 0. Many apps map the number to localized labels or use Intl.DateTimeFormat for locale-aware weekday names.
NaN. Validate with !Number.isNaN(date.getTime()) before using the result in conditionals or array lookups.
const day = date.getDay(); const isWeekend = day === 0 || day === 6; // Sunday or Saturday. For Monday–Friday use day >= 1 && day <= 5.
Did you know?

getDay() and getDate() are easy to mix up because of their names, but they answer completely different questions. A quick sanity check: February 26 returns weekday index 1 (Monday) while getDate() on the same date returns 26.

Continue to getFullYear()

Learn how to read the four-digit year from a Date object in local time.

getFullYear() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful