Home>

method 1:

function comparedate (dateone, datetwo) {
  var onemonth=dateone.substring (5, dateone.lastindexof ("-"));
  var oneday=dateone.substring (dateone.length, dateone.lastindexof ("-") + 1);
  var oneyear=dateone.substring (0, dateone.indexof ("-"));
  var twomonth=datetwo.substring (5, datetwo.lastindexof ("-"));
  var twoday=datetwo.substring (datetwo.length, datetwo.lastindexof ("-") + 1);
  var twoyear=datetwo.substring (0, datetwo.indexof ("-"));
  if (date.parse (onemonth + "/" + oneday + "/" + oneyear)>date.parse (twomonth + "/" + twoday + "/" + twoyear)) {
    return true;
  } else {
    return false;
  }
}

For example:

alert (comparedate ("" 2004-12-01 "", "" 2004-05-02 "" "));
Currently only supports year-month-day formats

Method 2:

var checkstartdate=document.form1.checkstartdate.value;
var checkenddate=document.form1.checkenddate.value;
var arys=new array ();
var startdate=new date (arys [0], parseint (arys [1] -1), arys [2]);
if (checkstartdate!=null&&checkenddate!=null) {
  arys=checkstartdate.split ("-");
  var startdate=new date (arys [0], parseint (arys [1] -1), arys [2]);
  arys=checkenddate.split ("-");
  var checkenddate=new date (arys [0], parseint (arys [1] -1), arys [2]);
  if (startdate&checkenddate) {
    alert ("The start time of your check date is greater than the end time");
    return;
  }
}
  • Previous Learn PHP design pattern PHP implementation memo pattern (Memento)
  • Next Difference between serializeArray () and serialize () in jQuery