Skip to content

JavaScript get day of month

  • by

You can use the Date object in JavaScript to get the day of the month. The getDate() method returns the day of the month (from 1 to 31) for the specified date according to local time.

var date = new Date().getDate();

JavaScript gets a day-of-month example

Simple example code getting the current day of the month.

<!DOCTYPE html>
<html>
<body>
    <script>
        const now = new Date();
        const dayOfMonth = now.getDate();
        console.log("Day of Month",  dayOfMonth);
    </script>
</body>
</html>

Output:

JavaScript get day of month

You can also pass a specific date to the Date constructor to get the day of the month for that date:

const date = new Date('2022-12-25');
const dayOfMonth = date.getDate();
console.log(dayOfMonth); // Output: 25

Do comment if you have any doubts or suggestions on this Js date object topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Tags:

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading