如何验证 JQuery 中的开始日期和结束日期?

How to validate From and To dates in JQuery?


我必须在使用 A​​jaxControlToolKit Calendar Extender 的 aspx 页面中验证两个日期。
以下是我的代码:

function DateValidation() {
    alert($("#txtfromDup").val() + "\n" + $("#txttoDup").val())
    var fromDate = Date.parse($("#txtfromDup").val());
    var toDate = Date.parse($("#txttoDup").val());
    alert(fromDate + "\n" + toDate);
    var timeDiff = toDate - fromDate;
    var daysDiff = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
    alert(daysDiff);
    if (daysDiff > 30) {
        alert('From Date shouldn\'t be less than To Date.');
        return false;
    } else
        return true;

}


未正确验证。
有人请帮我解决这个问题。

我会做类似的事情

var startdate = new Date( "2015-07-04");
var enddate = new Date( "2015-08-11");
var timeDiff = Math.abs(enddate.getTime() - startdate.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
alert(diffDays);
 //pseudo code:
  if (diffDays  > 30){
     //set timeFormat = "30days"
     alert('From Date shouldn\'t be less than To Date.');
    
 }else{
     alert('Valid.');  
 }