DEV Community

Discussion on: Vanilla JavaScript Check if Date is in the Past

Collapse
 
miketalbot profile image
Mike Talbot ⭐

Just a point - your routine has a side effect of actually modifying the date you passed in... Seems unwise. Perhaps:

dateInPastArrow = (firstDate, secondDate) =>
  new Date(firstDate).setHours(0, 0, 0, 0) <= new Date(secondDate).setHours(0, 0, 0, 0); 
Collapse
 
savagepixie profile image
SavagePixie • Edited

Also, shouldn't the comparison operator be just less than? If it's equal it's not past but present (or, to be more precise concurrent with the second date, since that could be any point in time)