Reputation: 305
In My monogdb I have Date column. I want to display the date in descending order with month and year wise. Date column:
14-03-2018
12-03-2018
13-03-2018
11-03-2018
10-02-2018
06-01-2018
09-01-2018
08-02-2018
07-01-2017
Expected result:
14-03-2018
13-03-2018
12-03-2018
11-03-2018
10-02-2018
08-02-2018
09-01-2018
07-01-2017
I used tr dir-paginate date on dates orderBy:'LastFollowupDate':'desc'" but is displaying what I expect
How to achieve this in angularjs
Upvotes: 1
Views: 1286
Reputation: 305
LastFollowDate has date: 14-03-2018
var Sort_date=$scope.GetInformations[i].LastFollowDate.split('-');//split date
$scope.$scope.GetInformations[i].oderdate= Sort_date[2]+Sort_date[1]+Sort_date[0];
The above code used to consider the whole number. It will consider as number like 20180314. if the date is 15-03-2018 it will consider as number like 20180315. It will increase the number count. So If I want to display the previous date using descending order ng-repeat
orderBy:'oderdate':'desc'
Upvotes: 0
Reputation: 38683
try this
$scope.sortDate= function(dt) {
var date = new Date(dt);
return date;
};
and
<table class="table table-bordered">
<tr>
<th>date</th>
</tr>
<tr ng-repeat="date in dates | orderBy : sortDate : true">
<td>{{date}}</td>
</tr>
</table>
Upvotes: 1