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


Posted 3 days Back


Posted 23 hours back

Is it possible to collaborate thse two:

get_comment_date(),  get_comment_time()

to get the above-mentioned effect?


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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