Trying to make a custom comments box. When I go to display the time when the comment was post (ie, 2 days ago, 3 hours ago, etc.) I get the same for every comment on every post: "48 Years"

$args = array(
        'number'  => '4',
        'post_id' => $id, // use post_id, not post_ID

$comments = get_comments( $args );

foreach ( $comments as $comment ) :

    // get the comments contents    

    echo $comment->comment_content;

    // human readable time when it was posted
    // this is where we get the "48 years" as when it was posted

    echo human_time_diff( $comment->comment_date, current_time( 'timestamp', 1 ) );


Whats up with that?


You should use strtotime to turn the comment's date into a string that can be compared with the current time. In your case, you should use:

echo human_time_diff( strtotime( $comment->comment_date ), current_time( 'timestamp', 1 ) );

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.