0

I have an array of objects where I am looping through to display data in the HTML using *ngFor. Each object also contains 2 dates , start and end.

How can I perform a calculation of the difference and display it in months / years on each object that being looped ?

what is the best way in this case to achieve this ! thanx

Yasir
  • 1,391
  • 2
  • 23
  • 44
  • Possible duplicate of [Get difference between 2 dates in javascript?](https://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript) – Hassan Imam Jul 10 '17 at 06:06

1 Answers1

2

Try this:

<div *ngFor="let item of items">{{getDiffDate(item.dateStart, item.dateEnd)}}</div>

getDiffDate(dateStart:Date, dateEnd:Date){
   return dateEnd.getTime() - dateStart.getTime() //result in miliseconds. Just convert it to whatever you want
}
Duannx
  • 7,501
  • 1
  • 26
  • 59