Compare two dates angularjs

后端 未结 3 1139
春和景丽
春和景丽 2021-01-03 06:20

I have two dates to be compared in the following format the response coming from backend service has following date format

alignFillDate - 2015-06-09 pickUpDate - 20

3条回答
  •  抹茶落季
    2021-01-03 07:00

    You save those date strings as Date objects, do a comparison with vanilla javascript and assign to scope or this.

       var alignFillDate = new Date("2015-06-09");
      var pickUpDate = new Date("2015-05-10");
    
    
      if (pickUpDate < alignFillDate) {
        alignFillDate = alignFillDate.setDate(alignFillDate.getDate() + 30);
      }
    
      $scope.pickUpDate = pickUpDate;
      $scope.alignFillDate = alignFillDate;
    

    Here is a plunk that does what you are trying to do http://plnkr.co/edit/Kq7WA1cBcrwDyxDeBFAL?p=info.

提交回复
热议问题