Skip to content Skip to sidebar Skip to footer

Moment.js Only Within The Last Week

I am using moment.js 'timeAgo' to display some dates. But I only want to use moment.js if the date is within the last week. (7 days ago) After that point I would just like to displ

Solution 1:

var someDate = moment.unix(<?php echo $date; ?>);
if(moment().diff(someDate, 'days') > 7){
    $("#date").append(someDate.format("dddd, MMMM Do YYYY"));
} else {
    $("#date").append(someDate.timeAgo());
}

Post a Comment for "Moment.js Only Within The Last Week"