Check If Two Dates Are The Same Day In JavaScript
1 min read

JavaScript date objects

Unfortunately, this is not a base functionality of the date object. Instead, we can use the getDate, getMonth and getFullYear methods to check if the dates are the same.

const sameDay = (firstDate, secondDate) =>
	firstDate.getFullYear() === secondDate.getFullYear() &&
	firstDate.getMonth() === secondDate.getMonth() &&
	firstDate.getDate() === secondDate.getDate();

The usage looks like this

const isSameDay = sameDay(new Date(), new Date()); // true