How to get the day of the week in JavaScript using getDay()?

Is it hard to get the day of the week in JavaScript?

Well, keep reading to discover the easy and simple way of getting the day using the getDay() method.

In this article, you’ll learn how to easily get the day of the week in JavaScript using the getDay() method of the Date object.

What is getDay() method?

The getDay() method is a built-in method of the Date object in JavaScript.

It returns the day of the week for a specified date, according to local time.

The value returned by this method is an integer that represents the day of the week, where 0 represents Sunday, 1 represents Monday, 2 represents Tuesday, and so on up to 6, which represents Saturday.

Syntax

Date.getDay()

Parameter

There is no parameter.

Return value

This method returns the day of the week with (0 to 6) for a specified date.

How to get the day of the week from date in JavaScript?

You can get the day of the week in JavaScrupt using the getDay() method of the Date object.

As what we mentioned a while ago that this method returns an integer between 0 and 6, where 0 represents Sunday and 6 represents Saturday.

Here’s an example of how to use the getDay() method to get the day of the week for a specific date:

const date = new Date("2023-08-02");
const dayOfWeek = date.getDay(); 
console.log(dayOfWeek);

We create a new Date object for August 2, 2023, and then use the getDay() method to get the day of the week for that date.

Output:

3

The method returns 3, that represents the day of week which is “Wednesday.”

You can also use an array of weekday names to get the name of the day of the week instead of just a number:

const weekdaynames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const date = new Date("2023-08-02");
const dayOfWeek = date.getDay(); 
console.log(weekdaynames[dayOfWeek]); 

As you have notice, in this example, we use an array of weekday names and index into it using the value returned by the getDay() method to get the name of the day of the week.

Output:

Wednesday

How to get the day of week and the month of the year in JavaScript?

To get the day of the week and the month of the year in JavaScript, you can use the getDay() and getMonth() methods of the Date object, respectively.

The getDay() method returns an integer between 0 and 6, where 0 represents Sunday and 6 represents Saturday. Meanwhile, the getMonth() method returns an integer between 0 and 11, where 0 represents January and 11 represents December.

Here’s an example of how to use these methods to get the day of the week and the month of the year for a specific date:

const date = new Date("2023-08-02");
const dayOfWeek = date.getDay(); 
const monthOfYear = date.getMonth(); 
console.log(dayOfWeek);
console.log(monthOfYear); 

As you can see, we create a new Date object for August 2, 2023, and then we use the getDay() and getMonth() methods to get the day of the week and the month of the year for that date.

Ourput:

3
7

The getDay() method returns 3, which represents “Wednesday,” and the getMonth() method returns 7, which represents August.

You can also use arrays of weekday names and month names to get the names instead of just numbers:

Here’s an example:

const weekdaynames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const monthnames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const date = new Date("2023-08-02");
const dayOfWeek = date.getDay(); ✅
const monthOfYear = date.getMonth(); 
console.log(weekdaynames[dayOfWeek]);
console.log(monthnames[monthOfYear]);

Here, we use arrays of weekday names and month names and index into them using the values returned by the getDay() and getMonth() methods to get the names of the day of the week and the month of the year.

Output:

Wednesday
August

Conclusion

In conclusion, getting the day of the week in JavaScript is not hard at all.

With the getDay() method of the Date object, you can easily get the day of the week for any date.

Apart from that, you can also use arrays of weekday names and month names to get the names of the day of the week and the month of the year.

We are hoping that this article provides you with enough information that help you understand on how to get the day of week in JavaScript.

You can also check out the following article:

Thank you for reading itsourcecoders 😊.

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.

Leave a Comment