3
<?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

4

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' ) ) ); ?>
5
  • Can you or someone help me to improve the title? so that it can be searchable in future?
    – WordCent
    Oct 1, 2017 at 11:51
  • Something like: "Change time output to: X time ago"
    – lukgoh
    Oct 1, 2017 at 11:55
  • 1
    I have changed the title as per your suggestions sir. Thanks for your help. accepted your answer.
    – WordCent
    Oct 1, 2017 at 11:57
  • 1
    No problem, I'm glad I could help you!
    – lukgoh
    Oct 1, 2017 at 11:57
  • cheers! and all the best on this website.
    – WordCent
    Oct 1, 2017 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.