How to check if a date is in the future with JavaScript

1 Answer

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

    return date > today;
}

console.log(isDateInTheFuture(new Date('2022-03-17'))); 
console.log(isDateInTheFuture(new Date('2022-02-6'))); 
  
   
   
   
   
/*
run:
   
true
false
   
*/

 



answered Mar 8, 2022 by avibootz
...