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
Fundamentals
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().
Concept
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).
Foundation
📝 Syntax
JavaScript
dateObj.getDay()
Parameters
None.
Return value
Integer 0–6 for a valid date in local time (0 = Sunday, 6 = Saturday).
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.
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
Meeting scheduled for today!
// or: No meeting today.
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.
Applications
🚀 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.
Important
📝 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.
Compatibility
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · 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.
Wrap Up
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.
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.