Get last seen date/time in wordpress get_comments() [closed]

I could get comment_date with a loop.
And it shows like 2018-03-19 12:30:06.
Here, I just want to get Last seen format.
(For instance, 3 min ago , 1 hour ago , 1 day ago , 2 week ago )

How can I achieve it?

["comment_date"]=>
string(19) "2018-03-19 12:30:06"
["comment_date_gmt"]=>
string(19) "2018-03-19 12:30:06"

1 Answer
1

WordPress already have such function in its core. It’s called ‘human_time_diff’ and it’s used in WP admin section.

Usage is pretty simple:

echo human_time_diff( $from, $to );

where $from is Unix timestamp from which the difference begins and $to is Unix timestamp to end the time difference (or time() by default).

So you’ll have to use strtotime function to convert date to timestamp.

Here you can find more info about it and some examples: https://codex.wordpress.org/Function_Reference/human_time_diff

Leave a Comment