Date comparison

by danielkwood

JavaScript

// Date is in format mm/dd/yyyy

// Example of comparing dates:

var date1 = new Date("11/14/2023");
var date2 = new Date("11/29/2023");

if (date1 > date2) {
  console.log("Date 1 is greater than Date 2");
} else if (date1 < date2) {
  console.log("Date 1 is less than Date 2");
} else {
  console.log("Both Dates are the same");
}

// Example of creating a date from separate variables

var day = 11;
var month = 12;
var year = 2023;

var customDateString = month + "/" + day + "/" + year;
var customDate = new Date(customDateString);