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

1 Answer

0 votes
function isDateBeforeToday(date : Date) {
  const today = new Date();
 
  today.setHours(0, 0, 0, 0);
 
  return date < today;
}
 
 
console.log(isDateBeforeToday(new Date('2022-03-11'))); 
console.log(isDateBeforeToday(new Date('2022-03-10'))); 
 
 
  
  
/*
run:
  
false
true
  
*/
 

 



answered Mar 11, 2022 by avibootz

Related questions

1 answer 250 views
1 answer 309 views
1 answer 275 views
1 answer 274 views
3 answers 312 views
1 answer 261 views
1 answer 269 views
...