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 display the date as normal. Example: (Jun 20, 2010) instead of (3 years ago).
I have the defaults working with this code. Any help would be great.
var date = moment.unix(<?php echo $date; ?>).fromNow();
$("#date").append(date);
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());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With