Comparing dates in jquery

前端 未结 7 1650
鱼传尺愫
鱼传尺愫 2020-12-10 04:08

I am having the following codes and it though i\'m having 01-Jan-2009 for DateTo and 03-Jan-2009 for DateFrom it\'s readi

相关标签:
7条回答
  • 2020-12-10 04:37

    here's more a simplified way from simple java script

    <script>
     //get the values
    function asdf(){
    var fDate=document.forms[0].fromDate.value;
    var tDate=document.forms[0].toDate.value;
    
    //Compare
    
    if(fDate>tDate){
            var dateComponentsfrom = fDate.split("/");
    
    //split and convert into date to be more precise
    
            var fromdate = new Date(dateComponentsfrom[2], dateComponentsfrom[1] - 1, dateComponentsfrom[0]);
            var dateComponentsto = tDate.split("/");
            var todate = new Date(dateComponentsto[2], dateComponentsto[1] - 1, dateComponentsto[0]);
            if(fromdate>todate){
                alert('from date cannot be greater than to date');
                return false;                        
            }
        }
    }
    </script>
    
    0 讨论(0)
提交回复
热议问题