Languages
[Edit]
EN

JavaScript - day name for specific Date

3 points
Created by:
lena
714

In this article, we would like to show you how to get the day name for a specific date in JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

const DAY_NAMES = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

const now = new Date();
const day = DAY_NAMES[now.getDay()];

console.log(day);

Note: in the above example we need to provide day names by ourselves to keep legacy with older JavaScript versions.

 

Practical example

// ONLINE-RUNNER:browser;

const DAY_NAMES = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];

const getDayName = (date) => {
	return DAY_NAMES[date.getDay()];  // day from 0 (Sunday) to 6 (Saturday)
};
  

// Usage example:

const now = new Date();

console.log(getDayName(now));

Example output:

Thursday

See also

  1. JavaScript - English day names 

Alternative titles

  1. JavaScript - get day name for specific Date
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join