VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-date-getdate-method/

⇱ JavaScript Date getDate() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Date getDate() Method

Last Updated : 11 Jul, 2025

The JavaScript getDate() method returns the day of the month (from 1 to 31) for a specified date according to local time.

It's used with the Date object to extract and work with the day component of a date.

Syntax:

DateObj.getDate()

Parameters:

  • This method does not take any parameters.

Return Value:

  • Returns the date of the month for the given date. The date of the month is an integer value ranging from 1 to 31.

Note: The DateObj is a valid Date object created using the Date() constructor from which we want to fetch the date.

Example 1: Extracting Day of the Month Using JavaScript Date getDate() Method

The code initializes a Date object with the date October 13, 1996, and then uses the getDate() method to extract the day of the month, which is 13. This value is printed to the console.


Output
13

Example 2: Extracting Day of the Month with Invalid Date Using JavaScript Date getDate() Method

The code initializes a date object with an invalid date string. Then, it attempts to extract the day of the month using getDate(). Since the date is invalid, it returns NaN.


Output
NaN

Example 3: Extracting Day from Year-Only Date

If date of the month is not given, by default it returns 1. It is an exceptional case.


Output
1

Example 4: Current Day Extraction

A Date object is created without parameters, representing the current date. getDate() extracts the day of the month from this object, which is then printed.

Comment