I was looking for a way to find out whether a Luxon
DateTime equals to today (
I couldn't find a utility method like the .isToday(date) from
So I found the following snippet that compares Dates solely based on the day. This allows you to figure out if a given DateTime is today.
const isToday = someDay.hasSame(DateTime.now(),"day")
Even though the name may be a misleading,
hasSame(DateTime,"day") doesn't only compare days it also makes sure the "Higher-order" units are identical.
So the date also has the same week, month and year.
The only caveat: Time zones are ignored by this method. So if you'd like to compare two dates from different timezones you first need to adjust one to the other with .setZone(zone) Or adjust both to the local timezone with .toLocal()