.getDate()
The .getDate()
method returns the day of the month.
Syntax
myDate.getDate();
The return value of .getDate()
is an integer number between 1
and 31
representing the day of a month.
Example
Suppose there is a need to find out if it is before the 10th of the current month:
const today = new Date('June 22, 2021 10:41:30');if (today.getDate() < 10) {console.log('It is before the 10th!');} else {console.log('It is the 10th, or later!');}// Output: It is the 10th, or later!
Codebyte Example
The example below is runnable, and assigns the variable myDate
to a new given Date
, then the result of the .getDate()
method is stored in payDay
. Finally, a console.log
call prints this value to the screen:
All contributors
- cslylla58 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- EugeneGoh_51 total contributions
- cslylla
- christian.dinh
- Anonymous contributor
- EugeneGoh_
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.