Today I Learned

hashrocket A Hashrocket project

Luxon's hasSame function for DateTimes

Luxon’s .hasSame lets you easlity check if two DateTimes contain the same specified time unit (such as year, month, or day).

import { DateTime } from "luxon";

const a = DateTime.local(2025, 8, 15, 10);
const b = DateTime.local(2025, 8, 15, 22);

a.hasSame(b, "day");
// true
a.hasSame(b, "hour"); 
// false
a.hasSame(b, "month"); 
// true
See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.