Moment.js only in the last week

I use time.js "timeAgo" to display some dates. But I want to use moment.js only if the date is in the last week. (7 days ago) After this point, I just wanted to show the date as usual. Example: (June 20, 2010) instead of (3 years ago).

I have default options working with this code. Any help would be great.

var date = moment.unix(<?php echo $date; ?>).fromNow(); $("#date").append(date); 
+4
source share
1 answer
 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()); } 
+7
source

Source: https://habr.com/ru/post/1487341/


All Articles