JavaScript getDate()

getDate() returns the day of the month for a JavaScript Date in local time. The result is an integer from 1 to 31.

const date = new Date("2026-09-10T12:00:00+05:30");
console.log(date.getDate()); // 10

Use getDate() for the date within the month. Do not confuse it with getDay(), which returns the weekday number.

getDate() Syntax and Return Value Top ↑

const dayOfMonth = date.getDate();

There are no parameters. A valid Date returns 1–31; an invalid Date returns NaN.

Get Today's Day of the Month Top ↑

const today = new Date();
const day = today.getDate();
console.log(day);

Formatting 1st, 2nd, 3rd and 4th Top ↑

If you need an English ordinal such as 21st, handle 11, 12 and 13 before looking only at the last digit.

function ordinal(day) {
  const mod100 = day % 100;
  if (mod100 >= 11 && mod100 <= 13) return `${day}th`;

  switch (day % 10) {
    case 1: return `${day}st`;
    case 2: return `${day}nd`;
    case 3: return `${day}rd`;
    default: return `${day}th`;
  }
}

console.log(ordinal(21)); // 21st

Pad the Day to Two Digits Top ↑

const day = String(date.getDate()).padStart(2, "0");

This is useful when assembling a custom DD/MM/YYYY-style display.

getDate() vs getUTCDate() Top ↑

const localDay = date.getDate();
const utcDay = date.getUTCDate();

Near midnight the local and UTC calendar dates can differ. Choose the method that matches the time basis of your application.

Invalid Dates Top ↑

const bad = new Date("invalid");
console.log(bad.getDate()); // NaN

Common getDate() Mistakes Top ↑

  • Confusing getDate() with getDay().
  • Assuming it returns a zero-based value. It returns 1–31.
  • Ignoring time zones when the instant is close to midnight.
  • Not checking whether the Date is valid.

Alert-window examples are available separately. getDay() Date Reference




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer