Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.

aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing
BlueHost Web Hosting

Bonsai Boy of New York Bonsai Trees and Accessories

Website Domains Names & Hosting | Domain.com

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

13,237 questions

18,022 answers

573 users

How to compare two dates in JavaScript

3 Answers

0 votes
let d1 = new Date(); 
let d2 = new Date(2020/5/18); 

if (d1.getTime() < d2.getTime()) 
    console.log("d1 < d2"); 
else if (d1.getTime() > d2.getTime()) 
        console.log("d1 > d2"); 
     else
        console.log("d1 === d2"); 
  
  
  
  
/*
run:
  
d1 > d2
  
*/
 

 




answered May 20 by avibootz
edited May 20 by avibootz
0 votes
let d1 = new Date(); 
let d2 = new Date(2020/5/19); 
  
console.log(d1.getTime() === d2.getTime()); 
  
  
  
/*
run:
  
false
  
*/

 




answered May 20 by avibootz
edited May 20 by avibootz
0 votes
let d1 = new Date(); 
let d2 = new Date(2020/5/19); 
  
console.log(d1.getTime() !== d2.getTime()); 
  
  
  
/*
run:
  
true
  
*/

 




answered May 20 by avibootz
edited May 20 by avibootz
...