Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Compare Two Dates Using JavaScript</title> </head> <body> <script> // Sample dates var date1 = new Date("August 15, 1994"); var date2 = new Date("December 10, 2022 04:30:00"); var date3 = new Date("2022-12-10T04:30:00"); // Performing comparison document.write(date1.getTime() == date2.getTime()); // Prints: false document.write("<br>"); document.write(date1.getTime() == date3.getTime()); // Prints: false document.write("<br>"); document.write(date2.getTime() == date3.getTime()); // Prints: true document.write("<br>"); document.write(date2.getTime() != date3.getTime()); // Prints: false document.write("<br>"); document.write(date1.getTime() > date2.getTime()); // Prints: false document.write("<br>"); document.write(date1.getTime() < date2.getTime()); // Prints: true document.write("<br>"); document.write(date1.getTime() != date2.getTime()); // Prints: true </script> </body> </html>