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 165 views
1 answer 172 views
1 answer 175 views
1 answer 157 views
1 answer 226 views
1 answer 165 views
1 answer 178 views
...