.getDay()
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:
All contributors
- cslylla54 total contributions
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- Anonymous contributorAnonymous contributor51 total contributions
- cslylla
- christian.dinh
- Anonymous contributor
- Anonymous contributor
Looking to contribute?
- 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.