Response from CD.. is correct but a filter seems appropriate for your use case:
Your html:
<ul>
<li ng-controller="Orders" ng-repeat="order in orders">
{{order.product}} | {{order.dateOrder | getDateDiffInDays}}
</li>
</ul>
Your application:
var app = angular.module('myApp', []);
app.filter('getDateDiffInDays', function() {
return function(myDate) {
var t1 = new Date().getTime();
return parseInt((t1 - myDate) / (24 * 3600 * 1000), 10);
};
});
app.controller('Ctrl', ['$scope', function($scope) {
$scope.orders = [
{ product: 'foo', dateOrder: new Date(2014, 0, 1) },
{ product: 'bar', dateOrder: new Date(2013, 0, 1) }
];
}]);
It is easy because you make a diff with current date, but if you need more complex diff, you can give parameter to your filter:
Your html:
<ul>
<li ng-controller="Orders" ng-repeat="order in orders">
{{order.product}} | {{order.dateOrder | getDateDiffInDays:today}}
</li>
</ul>
Your application:
var app = angular.module('myApp', []);
app.filter('getDateDiffInDays', function() {
return function(myDate, baseDate) {
// Second parameter can be optional
var t1 = (baseDate || new Date()).getTime();
return parseInt((t1 - myDate) / (24 * 3600 * 1000), 10);
};
});
app.controller('Ctrl', ['$scope', function($scope) {
$scope.today = new Date();
$scope.orders = [
{ product: 'foo', dateOrder: new Date(2014, 0, 1) },
{ product: 'bar', dateOrder: new Date(2013, 0, 1) }
];
}]);
Now you have a reusable filter.
See this fiddle: http://jsfiddle.net/n78k9/2