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 165 views
1 answer 206 views
1 answer 178 views
1 answer 188 views
3 answers 108 views
1 answer 165 views
1 answer 175 views
...