Search code examples
phpdateformattingrelative-date

How might I format relative dates the way Stack Overflow does "member since" and "last seen"?


Possible Duplicate:
How do I calculate relative time?

I want to know how to display these data as seen on stackoverflow.com profile page. I have the timestamp of users registered date and last visit date. But I need to display using stackoverflow.com format.

For example:

Member since: 9 months
Last seen: just now

Is there any script to convert these dates and display in such format?


Solution

  • This is a duplicate of this question which is a duplicate of this question which has some great code samples including PHP.

    In addition to all this, if are you using jQuery you can do this client-side with something like the timeago plugin. It has the advantage of updating the text as time passes so if you load a page and it says "posted 5 minutes ago" and look again 5 minutes later, it says "posted 10 minutes ago"