To Get the First and Last Day of the Current Week in JavaScript, you can use the “Date” object.
Here’s a step-by-step guide:
- Access the current index of the day of the week using the above-discussed getDay() function.
- Access the current date using the getDate() function.
- If we subtract the date from the day, we get the first day of the week.
- For getting the last day of the week, we need to add 6 to the value.
- Keep in mind that Sunday is the first day of the week ‘0’, and Saturday is the last day of week ‘6’
Example
let date_today = new Date();
console.log(`The current day index of the week is: ${date_today.getDay()}`);
console.log(`The current date of the week is: ${date_today.getDate()}`);
let first_day_of_the_week = new Date(date_today.setDate(date_today.getDate()
- date_today.getDay() ));
let last_day_of_the_week = new Date(date_today.setDate(date_today.getDate()
- date_today.getDay() + 6));
console.log(`The first date of the week is: ${first_day_of_the_week}`);
console.log(`The last day of the week is: ${last_day_of_the_week}`);
Output
The current day index of the week is: 1
The current date of the week is: 26
The first date of the week is: Sun Sep 25 2022 11:57:42 GMT+0530 (India Standard Time)
The last day of the week is: Sat Oct 01 2022 11:57:42 GMT+0530 (India Standard Time)
Explanation
The above code can be explained as follows:
- We first created the variable named date_today using the let keyword.
- Now we initialize the variable with the help of the new Date() constructor.
- We first printed the current day index of the week and the current date using the functions getDay() and getDate() functions, respectively.
- Then we created another variable named first_day_of_the_week and initialized it too. Also, we have subtracted the current day index from the current date.
- We then used the setDate() function to set the obtained date.
- We did a similar operation of the last_day_of_the_week variable.
- Finally, we printed them.
But If you want Monday to be the first day of the week and Sunday to be the last day of the week, you can use below code snippet.
let date_today = new Date();
console.log(`The current day index of the week is: ${date_today.getDay()}`);
console.log(`The current date of the week is: ${date_today.getDate()}`);
let first_day_of_the_week = new Date(date_today.setDate(date_today.getDate()
- date_today.getDay() + 1));
let last_day_of_the_week = new Date(date_today.setDate(date_today.getDate()
- date_today.getDay() + 7));
console.log(`The first date of the week is: ${first_day_of_the_week}`);
console.log(`The last day of the week is: ${last_day_of_the_week}`);
Output
The current day index of the week is: 1
The current date of the week is: 26
The first date of the week is: Mon Sep 26 2022 12:17:42 GMT+0530 (India Standard Time)
The last day of the week is: Sun Oct 02 2022 12:17:42 GMT+0530 (India Standard Time)
That’s it!

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.