- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to determine if date is weekend in JavaScript?
As we know the value 0 is for day Sunday and 6 for Saturday. First of all, you need to get day with the help of getDay().
Let’s set a date −
var givenDate=new Date("2020-07-18");
Now, we will get the day −
var currentDay = givenDate.getDay();
Following is the code to determine if date is weekend −
Example
var givenDate=new Date("2020-07-18"); var currentDay = givenDate.getDay(); var dateIsInWeekend = (currentDay === 6) || (currentDay === 0); if(dateIsInWeekend==true){ console.log("The given date "+givenDate+" is a Weekend"); } else { console.log("The given date " +givenDate+"is a not a Weekend"); }
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo66.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo66.js The given date Sat Jul 18 2020 05:30:00 GMT+0530 (India Standard Time) is a Weekend
- Related Articles
- How to check whether the given date represents weekend in Java
- How to determine if JavaScript object is an event?
- How to determine if a number is odd or even in JavaScript?
- How to determine if an argument is sent to the JavaScript function?
- How to determine if C# .NET Core is installed?
- How to convert epoch Date to meaningful JavaScript date?
- How to convert a MySQL date to JavaScript date?
- How to see if a date is before or after another date in Java 8?
- How to check whether a JavaScript date is valid?
- How to get yesterday’s date in JavaScript?
- How to sort date array in JavaScript
- How to format date value in JavaScript?
- How to subtract date from today's date in JavaScript?
- How to create JavaScript Date object from date string?
- How to format a JavaScript date?

Advertisements