.getDate()
Published Jun 22, 2021Updated May 24, 2023
Contribute to Docs
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:
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