This question already has an answer here:
How to find the time elapsed since a date time stamp like 2010-04-28 17:25:43
, final out put text should be like xx Minutes Ago
/xx Days Ago
This question already has an answer here:
How to find the time elapsed since a date time stamp like 2010-04-28 17:25:43
, final out put text should be like xx Minutes Ago
/xx Days Ago
You can get a function for this directly form WordPress core files take a look here
http://core.trac.wordpress.org/browser/tags/3.6/wp-includes/formatting.php#L2121
Had to do this recently - hope this helps someone. It doesn't cater for every possibility, but met my needs for a project.
https://github.com/duncanheron/twitter_date_format
https://github.com/duncanheron/twitter_date_format/blob/master/twitter_date_format.php
To improve upon @arnorhs answer I've added in the ability to have a more precise result so if you wanted years, months, days & hours for instance since the user joined.
I've added a new parameter to allow you to specify the number of points of precision you wish to have returned.
If you use the php Datetime class you could use:
One option that'll work with any version of PHP is to do what's already been suggested, which is something like this:
That will give you the age in seconds. From there, you can display it however you wish.
One problem with this approach, however, is that it won't take into account time shifts causes by DST. If that's not a concern, then go for it. Otherwise, you'll probably want to use the diff() method in the DateTime class. Unfortunately, this is only an option if you're on at least PHP 5.3.
Most of the answers seem focused around converting the date from a string to time. It seems you're mostly thinking about getting the date into the '5 days ago' format, etc.. right?
This is how I'd go about doing that:
I haven't tested that, but it should work.
The result would look like
or
cheers