The first date as a Date object or timestamp (number)
The second date as a Date object or timestamp (number)
True if both dates are in the same month and year, false otherwise or if either date is invalid
// Same month and year, different days
const result = isSameMonth(new Date(2024, 5, 1), new Date(2024, 5, 30));
// Returns: true
// Different months
const result2 = isSameMonth(new Date(2024, 5, 30), new Date(2024, 6, 1));
// Returns: false
// Same month and year, different times
const result3 = isSameMonth(
new Date(2024, 5, 15, 14, 30),
new Date(2024, 5, 20, 9, 45)
);
// Returns: true
// Same month, different years
const result4 = isSameMonth(new Date(2024, 5, 15), new Date(2023, 5, 15));
// Returns: false (different years)
// Invalid dates return false
const result5 = isSameMonth(new Date("invalid"), new Date(2024, 5, 1));
// Returns: false
Check if two dates are in the same calendar month and year.
This function compares two dates and returns true if they fall within the same calendar month and year, regardless of day or time components.