Encodera

Thanks for reading!

Donate to the site — we work hard for you.

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:

6

The 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
Sa

Monday 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
1

Common 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 6

Functions used in this recipe

Thanks for reading!

Donate to the site — we work hard for you.