0

I just started with AngularJS and got stuck with a problem.

I have a date field to show in a grid. Date format should be relative format like "1 day ago, 10 mins ago...." So for that i used timeAgo, so it formats the date correctly.

But I have a requirement like:

If the last_updated_time is less than 10 days, then show relative time like "1 day ago, 10 mins ago...." else do not apply any filter.

Here is my code snippet.

<td data-title="'Last modified'" sortable="'last_updated_time'" align='center'>
    {{offer.last_updated_time | timeAgo }}
</td>

It would be great if someone can guide me how to proceed.

1 Answer 1

4

Use a function to get this:

$scope.getTimeAgo = function(last_updated_time ){
     var today = new Date();
     var days = today.diff(last_updated_time , 'days');
     if(days > 10)
        return last_updated_time;
     else
        return moment(last_updated_time).fromNow();
 };

then you can use it like follow:

{{getTimeAgo(offer.last_updated_time)}}

PS: I'm using momentjs for time ago but you can apply your time ago function into the else if you want to use your filter.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi nramirez, I apologize for the delayed reply... Thanks a ton for the answer... My requirement got changed slightly, so took another approach to solve... Thanks for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.