Find the Day of the Week from a Date in JavaScript

To find the weekday for a calendar date, create a valid Date, call getDay(), and map the returned number 0–6 to Sunday through Saturday. For user-entered calendar dates, build the Date from numeric year, month, and day components so the result is not shifted by UTC parsing.

const date = new Date(2026, 8, 10);
const names = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
console.log(names[date.getDay()]); // Thursday
Choose a date and select Display Day.

How getDay() Works Top ↑

getDay() returns the weekday according to local time: 0 for Sunday through 6 for Saturday. Do not confuse it with getDate(), which returns the day of the month.

const dayNumber = date.getDay(); // 0 to 6
const weekday = names[dayNumber];

Read and Validate an Entered Date Top ↑

An HTML date input returns a string in YYYY-MM-DD form. Split the parts and construct a local Date with numeric components. Then compare the resulting components with the input to catch impossible dates.

const [year, month, day] = inputValue.split("-").map(Number);
const date = new Date(year, month - 1, day);
const isValid = date.getFullYear() === year &&
  date.getMonth() === month - 1 &&
  date.getDate() === day;

Manual Date Strings with split() Top ↑

The original Plus2net project accepted a slash-separated date and used split(). If you must accept text input, specify the expected format clearly and validate every part before constructing a Date.

const [month, day, year] = "09/10/2026".split("/").map(Number);
const date = new Date(year, month - 1, day);

Get a Localized Weekday Name Top ↑

Instead of maintaining an English weekday array, Intl.DateTimeFormat can produce names for the user's locale.

const formatter = new Intl.DateTimeFormat("en-US", { weekday: "long" });
console.log(formatter.format(date));

Local-Time and UTC Considerations Top ↑

A date-only ISO string such as "2026-09-10" is parsed as UTC by JavaScript. Calling local getters on that value can show the previous calendar day in time zones west of UTC. For a user's local calendar date, constructing from numeric components avoids that trap. If your application is intentionally UTC-based, use getUTCDay() consistently instead.

Date Reference All Date Projects




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer