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