How to check if a date is today date in TypeScript

1 Answer

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

  if (today.toDateString() === date.toDateString()) {
      return true;
  }

  return false;
}

console.log(isTodayDate(new Date())); 
console.log(isTodayDate(new Date('2022-03-12'))); 

  
  
  
/*
run:
        
true
false
      
*/

 



answered Mar 11, 2022 by avibootz

Related questions

1 answer 180 views
1 answer 175 views
1 answer 167 views
1 answer 179 views
1 answer 174 views
1 answer 159 views
1 answer 167 views
...