Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  111] [ 3]  / answers: 1 / hits: 81282  / 9 Years ago, mon, june 1, 2015, 12:00:00

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 - 2015-05-10



so, front end needs to check the condition is if pickUpDate is less then the alignFillDate, we will increase the alignFillDate by 30 days, i.e, we increment the pickUpDate to next month(30 days from now ) and show different text on view



How, do i achieve this using angular and javascript. ? how does my html and controller needs to changed for this date calculation


More From » angularjs

 Answers
138

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.


[#66384] Friday, May 29, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
santana

Total Points: 595
Total Questions: 94
Total Answers: 98

Location: Zambia
Member since Mon, Oct 24, 2022
2 Years ago
;