I'm building this app that get articles from a DB and 1 of the fields is the date which right now is in format '2019-06-13T18:03:58.000Z' and basically what I need to do is check if this is today's date return onyl the hours and am/pm so for this example is today so return 18:03pm, if the date is the same as yesterday's then return 'yesterday'and if the date is other than those then return 'Month, day'
I've tried creating Date objects and then compare but it didn't work
I have this code for the html:
<div class='date-container'>
{{renderDate(data.created_at)}}
</div>
and in the component.ts file:
public renderDate(date) {
const fecha = new Date(date);
const today = new Date();
const yesterday = today.getDate()-1;
let fecha_r = '';
if(fecha.getTime() == today.getTime()){
fecha_r = 'today';
}
return fecha_r;
}
I need to return the converted date in that function so my html code prints the correct formated date how can I do this?