Date getters (getMonth, getDate, getDay…)
Nine methods that read the parts of a date. Two things to hold onto: months count from zero while days of the month count from one, and every one of these is local time.
Demo
The four numbers are [year, month, date, day]. Look at the first case: a date in MARCH reports month 2, because getMonth counts from zero — while getDate reports 15, counting from one. Two adjacent methods on the same object with different bases, which is why so much date code is off by one month. The fourth number is getDay, the day of the WEEK (0 is Sunday), not the day of the month — another pair of confusingly similar names. An invalid date gives NaN from every getter rather than throwing.
Common patterns
const s = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`;
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; DAYS[d.getDay()];
d.toLocaleDateString('en-GB', {month: 'long'});
Examples
Pitfalls
`${d.getUTCMonth()}/${d.getUTCDate()}`
`${d.getUTCMonth() + 1}/${d.getUTCDate()}`
new Date('2026-03-15T12:00:00Z').getUTCDay()
new Date('2026-03-15T12:00:00Z').getUTCDate()
new Date('2026-03-15T23:00:00Z').getDate()
new Date('2026-03-15T23:00:00Z').getUTCDate()
new Date('2026-03-15T12:00:00Z').getYear()
new Date('2026-03-15T12:00:00Z').getFullYear()
When to use
- Reading a single component for arithmetic or comparison
- Building a custom format where Intl options do not fit
- Grouping records by local day, month or weekday
- Formatting for a reader → toLocaleDateString with Intl options
- The answer must not depend on the runtime → the getUTC family
- Serialising → toISOString
- getYear, ever → getFullYear
Notes
FAQ
Because it was designed to index an array of month names, in an era when that was how you formatted a date. getDate had no such use and stayed one-based. The inconsistency has been in the language since 1997 and cannot be changed.
const MONTHS = ['Jan', 'Feb', 'Mar']; MONTHS[d.getMonth()]; // the original intent