JavaScript getDate() method explained with code examples

Posted on Mar 22, 2022

Learn how the getDate() method works with JavaScript code examples

The JavaScript getDate() method is a method of the Date object that allows you to retrieve the day of the month of a given date.

This method has no parameters and can be called from any valid Date object.

Here’s an example of the getDate() method in action:

const date = new Date(); // 22nd March 2022 local time

const day = date.getDate();
console.log(day); // 22

The getDate() method will return an integer number between 1 and 31 that represents the day of the month.

You can get the day of the month from a specified date like this:

const date = new Date("January 01, 2010 10:20:20");

const day = date.getDate();
console.log(day); // 1

And that’s how the getDate() method works. 😉

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.