snew
snew

Reputation: 101

want to show a time for the comment last posted through php

I want to show when the comment last posted in PHP. like 5 minutes ago, 2 days ago, 7 weeks ago. How to do this?

Upvotes: 1

Views: 999

Answers (4)

Anurag
Anurag

Reputation: 141889

You can find plenty of answers with full solutions in different languages, pseudocode, ideas, etc.. here.

I believe there's an example of PHP too.

Upvotes: 1

Ranga
Ranga

Reputation: 11

Store the comment posted in the date DB and show the the same in the front end by comparing with current date and time using php function

Upvotes: 0

Donny Kurnia
Donny Kurnia

Reputation: 5313

You can do manual calculation in server, to get the time difference, then translate it into human time format.

Or my preference, do it in browser using javascript. Using this approach, the time in page can be updated without refresing the page.

You can use this jQuery EasyDate library to translate a DOM element into humane time format.

You can also read the comments in this post about Pretty Date by John Resig. It contain the code, and improvement by other.

Upvotes: 0

Tyler Carter
Tyler Carter

Reputation: 61577

You can use timeago, a jQuery plugin, to do it via Javascript. It would yield the same result, update without refreshing, and by doing it client side instead of server side, you are not precluded from caching.

http://timeago.yarp.com/

Otherwise, Annurag has a link with some good PHP solutions.

Upvotes: 0

Related Questions