This article will show you how to get the Saturday of the current week in JavaScript in the simplest ways. You can apply for similar cases if you need other weekdays. Read on and practice with each example.
How to get the Saturday of the current week in JavaScript quickly?
Using setDate(), getDate(), getDay() functions
We have introduced the syntax of setDate()
, getDate()
, getDay()
functions in the previous post. You can read it here.
We will create the Date object using the new Date()
syntax.
Next, we get the current day of the month by using the getDate()
function and get the current day of the week (0 – 6) by using the getDay()
function. After getting the day of the week, we will check if it is equal to 6 or not. If it is 6, then it is Saturday. If not, then Saturday is calculated by the following formula:
Saturday = The day of the month - The day of the week + 6
Finally, we pass the number we have calculated above to the setDate()
function to get the Saturday of the current week.
Use the toLocaleDateString()
function if you want to display only the year’s date!
Look at the sample code below to better understand.
let currentDate = new Date(); if (currentDate.getDay() == 6) { // Today is Saturday let saturday = currentDate; console.log(`today ${saturday.toLocaleDateString()} is Saturday!`); } else { // First day of the week = The day of the month - The day of the week let firstDay = currentDate.getDate() - currentDate.getDay(); // Saturday = The first day of the week + 6 let saturday = firstDay + 6; // Use setDate() to make Saturday object saturday = new Date(currentDate.setDate(saturday)); console.log('Saturday of the current week: ' + saturday.toLocaleDateString()); }
Output:
Saturday of the current week: 10/15/2022
Adding getSaturday() function to the Date prototype
This is based on the idea of the first method, but the difference is that we will add the getSaturday()
function to the Prototype of Date. Later, whenever we need, we only call the function with a command, and we will get the result. Like this:
// Add getSaturday() to Date Prototype Date.prototype.getSaturday = function () { let saturday = this.getDate() - this.getDay() + 6; // this = Date object return new Date(this.setDate(saturday)); }; let date = new Date(); // Get Saturday console.log('Saturday of this week: ' + date.getSaturday().toLocaleDateString());
Output:
Saturday of this week: 10/15/2022
Using the moment.js library
This is the simplest of the three methods. But it requires you to import an external library into your project.
If you don’t mind, then try this method!
To use moment.js, you must import it. You can import the library manually or use the CDN. Here we use the CDN for its convenience.
With moment.js, we can use the moment()
instead of the new
keyword to create a Date object. To get Saturday of the current week, we only need a line of code:
moment().day('Saturday')
Like this:
let saturday = moment().day('Saturday'); console.log('Saturday of this week: ' + saturday.format('MM/DD/YYYY'));
Output:
Saturday of this week: 10/15/2022
Since Saturday is the weekend, we can also use the endOf('week')
function to get Saturday. Like this.
let saturday = moment().endOf('week'); console.log('Saturday of this week: ' + saturday.format('MM/DD/YYYY'));
Output:
Saturday of this week: 10/15/2022
Summary
We have shown you 3 ways to get the Saturday of the current week in JavaScript. We recommend the 3rd method if you don’t mind importing external libraries into the project. Hopefully, this article is useful for you. Have a lucky day!
Maybe you are interested:
- How To Get the Number of Days in a Month in JavaScript
- Get the Day Name from a specific Date using JavaScript
- Get Date and Time in User’s locale format in JavaScript

Hi, I’m Cora Lopez. I have a passion for teaching programming languages such as Python, Java, Php, Javascript … I’m creating the free python course online. I hope this helps you in your learning journey.
Name of the university: HCMUE
Major: IT
Programming Languages: HTML/CSS/Javascript, PHP/sql/laravel, Python, Java