How to get the day of the week
Short answer
getDay() returns a number from 0 to 6, where 0 is Sunday:
const date = new Date(2025, 2, 15);
console.log(date.getDay());Output:
6The name of the day
toLocaleDateString() with the weekday option returns the name in the needed language:
const date = new Date(2025, 2, 15);
console.log(date.toLocaleDateString('en-US', { weekday: 'long' }));
console.log(date.toLocaleDateString('de-DE', { weekday: 'short' }));Output:
Saturday
SaMonday as day 1
In many countries the week starts on Monday. Shift the numbers so that Monday is 1 and Sunday is 7:
const isoDay = (date) => date.getDay() || 7;
console.log(isoDay(new Date(2025, 2, 16)));
console.log(isoDay(new Date(2025, 2, 17)));Output:
7
1Common mistake
getDate() and getDay() are easy to confuse. The first one is the day of the month:
const date = new Date(2025, 2, 15);
console.log(date.getDate(), date.getDay());Output:
15 6Functions used in this recipe
- Date.prototype.getDay — Returns the day of the week — a number from 0 to 6, where 0 is Sunday.
- Date.prototype.toLocaleDateString — Formats a date without time by language rules.