validate end date equal to greater than start date

前端 未结 2 1435
清酒与你
清酒与你 2021-01-20 20:52

I want to check whether end date is greater than or equal to start date, with jquery validate. It is validating end date greater than start date, but it is not permitting en

2条回答
  •  星月不相逢
    2021-01-20 21:45

    If you want to use simple javascript to compare ethe date. Here is one; simple and easier.

     function compareDate() {
        var str = document.getElementById("start_date").value;
        var end = document.getElementById("end_date").value;
        var year = str.substring(0,4);
        var month = str.substring(5,7);
        var date = str.substring(8,10);
        var endYear = end.substring(0,4);
        var endMonth = end.substring(5,7);
        var endDate = end.substring(8,10);
        var startDate = new Date(year, month-1, date);
        var endDate = new Date(endYear, endMonth-1, endDate);
    
        if (startDate > endDate) {
          alert('start date should be less than end date');
           return false;
        } 
        else { return true; }
    }
    

提交回复
热议问题