How to check 2 date fields and compare to see which date is ahead, behind or the same

前端 未结 3 910
清酒与你
清酒与你 2021-01-26 11:00

I\'m working with 2 dates that are posted back to me in a textbox as strings in this format 03/02/2010. One is the current completion date and the second is the final completion

3条回答
  •  醉梦人生
    2021-01-26 11:35

    var passedDate1 = new Date('03/02/2010');
    var passedDate2 = new Date('03/01/2010');
    
    if (passedDate1 > passedDate2) {
       alert ('Date1 is greated than date 2');
    }
    else if (passedDate1 < passedDate2) {
       alert ('Date1 is less than date 2');
    }
    else {
       alert ('they are equal');
    }
    

提交回复
热议问题