javascript a simple way to compare date sizes

  • 2020-11-18 06:07:50
  • OfStack

This article illustrates javascript's simple method for comparing date sizes. To share for your reference, the details are as follows:


// Get start date 
var startDate=document.all.startdate.value;
// Convert to date format 
startDate=startDate.replace(/-/g,"/");
// Get end date 
var endDate=document.all.enddate.value;
endDate=endDate.replace(/-/g,"/");
// If the start date is greater than the end date 
if(Date.parse(startDate)-Date.parse(endDate)>0){
 alert(" The start date should precede the end date !");
 // return false
 return false;
}

I hope this article has been helpful in JavaScript programming.


Related articles: