Search code examples
angularjsmomentjsangular-moment

Calculating difference between dates with amDifference filter


Plunker

I have a questions about using the amDifference filter in angular-moment.

Currently I have it set up like this:

{{order.shipDate | amDifference: null: 'days'}}

Which is calculating the difference between the ship date and the current date, but it is backwards with what I need if for. For example, if my shipDate was on 12/05/2015 it is currently showing '-81', but I would like for it to show '81'. So I guess something like this:

{{currentDate | amDifference: order.shipDate: 'days'}}

I have already tried this:

{{null | amDifference: order.shipDate: 'days'}}

Which didn't work.

So I guess I want to know:

  1. Am I using the right angular-moment filter?
  2. If I can use this filter, how do I accomplish it?

Thanks so much!


Solution

  • Just set a variable for today in controller

    $scope.today = new Date();
    

    Then do

    <td>{{ today | amDifference:  order.shipDate : 'days'}} days</td>
    

    DEMO