How to check if a date is before today date using JavaScript

1 Answer

0 votes
function isDateBeforeToday(date) {
  const today = new Date();

  today.setHours(0, 0, 0, 0);

  return date < today;
}


console.log(isDateBeforeToday(new Date('2022-03-10'))); 
console.log(isDateBeforeToday(new Date('2022-03-9'))); 


 
 
/*
run:
 
false
true
 
*/

 



answered Mar 10, 2022 by avibootz

Related questions

1 answer 245 views
1 answer 254 views
1 answer 263 views
1 answer 250 views
1 answer 323 views
1 answer 255 views
1 answer 268 views
...