.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
:
0
meaning Sunday1
meaning Monday2
meaning Tuesday3
meaning Wednesday4
meaning Thursday5
meaning Friday6
meaning 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
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours