change the comment time output to: X time ago instead of actual date and time

<?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?>

Above is the default code that exists for comments.php in the WP Core.

This will produce an Output like this:

enter image description here

October 1, 2017 at 6:58 am

But I want something like this →

Posted: 11 Months ago

or

Posted 3 days Back

or

Posted 23 hours back

Is it possible to collaborate thse two:

get_comment_date(),  get_comment_time()

to get the above-mentioned effect?

1 Answer
1

What you need is: https://codex.wordpress.org/Function_Reference/human_time_diff

So this should do exactly what you need:

 <?php printf( _x( '%s ago', '%s = human-readable time difference', 'your-text-domain' ), human_time_diff( get_comment_time( 'U' ), current_time( 'timestamp' ) ) ); ?>

Leave a Comment