I'm trying to calculate the difference between two dates that i'm getting from a backend service. im getting a list that contains date in this format : "dateTimeZ":"2021-09-22T12:41:56.133Z" So what im trying to do is that i want to show a new column that contains the difference betwwen the date in the current item with the previous one :
<div class="listHistory">
<table class="table">
<caption hidden>Actions List Table Description</caption>
<th scope="col">Object Id</th>
<th scope="col">Object</th>
<th scope="col">Object Name</th>
<th scope="col">Action</th>
<th scope="col">Action Author</th>
<th scope="col">Action Time</th>
<th scope="col">Amount of Time between Actions</th>
<tr scope="row" *ngFor="let action of caseActions?.results; let i = index" class="rowHistory">
<td>{{action.id}}</td>
<td>{{action.type}}</td>
<td>{{action.name}}</td>
<td>{{action.action}}</td>
<td>{{action.author}}</td>
<td>{{action.dateTimeZ | dateFormatter}}</td>
<td>{{amount(i)}}</td>
</tr>
</table>
</div>
in the .ts file i added a function amount(i) that will do the calculation and return the difference: if i=0 then it will return 0 because it doesn't have a previous one but how to calculate the rest to get it the result in this format : 1d 3h 15m
amount(i){
if(i==0){
return 0;
} else{
????????????
}
}