You can achieve the desired result without relying on momentjs.
Update:
If you want to take into account daylight saving time, avoid using getTime
and opt for Date.UTC
instead:
calculateDiff(data){
let date = new Date(data.sent);
let currentDate = new Date();
let days = Math.floor((Date.UTC(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()) - Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) ) /(1000 * 60 * 60 * 24));
return days;
}
<div *ngFor="let data of responseData" class="dataHolder">
<div>{{data.title}}</div>
<div>{{data.type}}</div>
<div>{{data.msg}}</div>
Message sent on: <div>{{data.sent}}</div>
<div style="font-weight:bold;">sent {{calculateDiff(data)}}_ days ago</div>
</div>
Previous Answer:
calculateDiff(data){
let date = new Date(data.sent);
let currentDate = new Date();
let days = Math.floor((currentDate.getTime() - date.getTime()) / 1000 / 60 / 60 / 24);
return days;
}
<div *ngFor="let data of responseData" class="dataHolder">
<div>{{data.title}}</div>
<div>{{data.type}}</div>
<div>{{data.msg}}</div>
Message sent on: <div>{{data.sent}}</div>
<div style="font-weight:bold;">sent {{calculateDiff(data)}}_ days ago</div>
</div>