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 year, false otherwise or if either date is invalid
// Same year, different months
const result = isSameYear(new Date(2024, 0, 1), new Date(2024, 11, 31));
// Returns: true
// Different years
const result2 = isSameYear(new Date(2024, 11, 31), new Date(2025, 0, 1));
// Returns: false
// Same year, different times
const result3 = isSameYear(
new Date(2024, 5, 15, 14, 30),
new Date(2024, 8, 20, 9, 45)
);
// Returns: true
// Works with timestamps
const result4 = isSameYear(Date.now(), Date.now());
// Returns: true
// Invalid dates return false
const result5 = isSameYear(new Date("invalid"), new Date(2024, 0, 1));
// Returns: false
Check if two dates are in the same calendar year.
This function compares two dates and returns true if they fall within the same calendar year, regardless of month, day, or time components.