Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 209
JessySue Avatar asked Oct 26 '25 09:10

JessySue


1 Answers

Just set a variable for today in controller

$scope.today = new Date();

Then do

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

DEMO

like image 105
charlietfl Avatar answered Oct 29 '25 08:10

charlietfl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!