JavaScript .getDay()
Published Jun 22, 2021Updated May 24, 2023
Contribute to Docs
The .getDay() method returns the day of the week.
Syntax
myDate.getDay();
The return value of .getDay() is an integer number between 0 and 6:
0meaning Sunday1meaning Monday2meaning Tuesday3meaning Wednesday4meaning Thursday5meaning Friday6meaning Saturday
Example
To determine if it is Friday or not:
const today = new Date('June 25, 2021 10:41:30');if (today.getDay() === 5) {console.log("It is Friday, let's have a coffee later!");} else {console.log('It is not Friday...');}// Output: It is Friday, let's have a coffee later!
Codebyte Example
The example below is runnable, and first, it defines today with today’s date, then the result of the .getDay() method is assigned to weekDay. Finally, a console.log call prints the value to the screen:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours