Skip to content

isSameDay

The isSameDay function checks if two dates represent the same day (year, month, and day).

Syntax

typescript
isSameDay(date1: Date, date2: Date): boolean;

Parameters

NameTypeDescription
date1DateFirst date
date2DateSecond date

Returns

TypeDescription
booleanTrue if both dates are on the same day

Examples

typescript
isSameDay(new Date("2024-06-10T10:00:00"), new Date("2024-06-10T23:59:59"));
// => true

isSameDay(new Date("2024-06-10"), new Date("2024-06-11"));
// => false

Notes

  • Throws an error if either date is invalid.
  • Useful for comparing dates while ignoring the time.

References

Released under the MIT License.