Project Management, WordPress

Time ago implementation in WordPress

Time ago can be implemented in the WordPress Post, using get_the_time() and human_time_diff() functions.

$postedTime = get_the_time(‘U’,$post->ID);
get_the_time() function retrieves the time at which the post was written.

human_time_diff( int $from, int $to ), determines the difference between two timestamps by providing the posted date of the post and current time.

$timeAgo = human_time_diff($postedTime ,current_time( ‘U’ ));


Click to learn more about get_the_time() and human_time_diff() functions in codex.

You can also use Carbon, a simple PHP API extension for DateTime to implement different formats of Date and Time.

Hits: 30