Rizka Nugroho Rizka Nugroho -4 years ago 119
AngularJS Question

How to subtract date in angularjs

I try make list from curent date until last 31 days. I try use

to make list today until 31 day. I can make list but not date. I try code like this


<ion-item class="animate-repeat" ng-repeat="i in rep">


$scope.rep = [];
for (var i=0; i < 31; i++) {
$scope.trip = new Date();
$scope.besok = $scope.trip.setDate($scope.trip.getDate()- i);

enter image description here

and it will show like this. It cannot subtract day. How to reduce it properly in angularjs ? please help me solved this problem. Thanks

Answer Source

Try like this. i know this is not angularjs code. same logic would work in both

var rep = [];
for (var i=0; i < 31; i++) {  
   var trip = new Date();
   var besok =new Date(trip.getTime() - i*(24*60*60*1000));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download