The JavaScript getDate function is one of the date functions, which is useful for returning the day of the month number (1 to 31) from a given date. We can use the getDate() function to extract the day of the month number from the current date or a custom date.
JavaScript getDate() syntax
The syntax of the getDate() function is
dateObject.getDate()
Parameters: This method does not accept any parameters.
Return Value: The getDate() function returns an integer value between 1 and 31. It represents the day of the month number from a given date. As the month starts at 1 and has a maximum of 31 days, it returns a number between 1 and 31.
JavaScript getDate() example
The following example helps you understand the getDate() Function. Here, we are using getDate to return the day of the month from the current datetime.
const dt = new Date();
console.log("Date =", dt.toString());
console.log("Day of the Month =", dt.getDate());
Date = Fri Jun 05 2026 14:45:41 GMT+0530 (India Standard Time)
Day of the Month = 5
Example 2: Get the day of the month from a custom date
In the following JavaScript example, we used the Date() method to build a date object from a custom date. Next, we used the JavaScript getDate() function to extract the day of the month number from the custom date and time.
const dt = new Date('December 22, 2025 10:09:07');
console.log("Day of the Month =", dt.getDate());
Day of the Month = 22
Example 3: Validating a day
There are a few organization shares revenue at the end of the month. We can use the if else statement with getDate() to check whether today is a pay date or any specific date.
const dt = new Date("05-21-2026");
if (dt.getDate() === 21)
{
console.log('Google credited Money');
}
else
{
console.log('Wait a few more days');
}
Google credited Money
NOTE: Replace 21 with 1 to check whether it is the first day of the month.
Example 4: Checking whether we passed half of the month
Similar to the above example, we can use the getDate() function to check whether we passed half of the month. Otherwise, are we in the first half of the month or the second half?
const dt = new Date("05-21-2026");
if (dt.getDate() < 15)
{
console.log('Its the First half of the month');
}
else
{
console.log('Its the Second half of the month');
}
Its the Second half of the month
JavaScript getDate 2 digits
By default, the getDate() function returns the day number from 1 to 31. It means dates between 1st and 10th are returned as single digit and the remaining are 2 digits. To form a uniformity, we convert the current date and time to a string and then use the padStart() function.
const date = new Date();
const day = String(date.getDate()).padStart(2, '0');
console.log(day);
09
JavaScript getDate returns the previous day
When we pass a string date to parse, the new Date() method creates a date object based on the local system date and time settings. As the system is in the Alaska time zone, which is in -9:00 hours time zone, it returns the previous day.
const date = new Date('2026-01-10');
const day = date.getDate();
console.log(day);
console.log(date);
9
Fri Jan 09 2026 15:00:00 GMT-0900 (Alaska Standard Time)
Difference between JavaScript getDate() and getDay()
Both getDate() and getDay() functions are built-in date and time functions.
- getDate(): It returns the day of the month number from 1 to 31.
- getDay(): It returns the day of the week from 0 (Sunday) to 6 (Saturday).
In the following example, we use the getDate() and getDay() functions on the custom date and time.
const dt = new Date("06-08-2026");
console.log("Date =", dt.toDateString());
console.log('Day of the Week =', dt.getDay());
console.log("Day of the Month =", dt.getDate());
Date = Mon Jun 08 2026
Day of the Week = 1
Day of the Month = 8
JavaScript increment date by 1
The getDate() function returns the date number and increments the date by 1. Next, the setDate() will set the date with this updated value.
const dt = new Date();
dt.setDate(dt.getDate() + 1);
console.log(dt);
Fri Jun 12 2026 12:28:33 GMT+0530 (India Standard Time)
JavaScript decrement date by 1
We must use the getDate() function and subtract 1 from it to decrement its date value by 1, and then setDate() to build the previous day’s date.
const dt = new Date();
dt.setDate(dt.getDate() - 1);
console.log(dt);
Wed Jun 10 2026 12:31:54 GMT+0530 (India Standard Time)