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()]); // ThursdaygetDay() 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];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;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);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));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
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.