Support » Fixing WordPress » Changing comment date format when looping $comments array

  • Resolved greg2008


    I’m using the $comments array to loop through each comment (simply because it gives me more flexibility than the wp_list_comments()).

    So to echo the current time and date per comment I have to use this (as far as I know):
    echo $comments[0]->comment_date;

    How do I change the format of the time and date output. Currently is this 2009-05-14 21:44:46, and I want this Thursday 14th May, 2009, 9:44pm ('l jS F, Y, g:ia')

    Would I have to change some hook(s) or core code?


Viewing 8 replies - 1 through 8 (of 8 total)
  • esmi


    Forum Moderator

    Use PHP’s date() function.

    Thanks for the reply.

    Use php date function with what? The data available is a textual output with spaces, hyphens and colons. I could strip all that away and use it in a date/timestamp fashion, but it seems messy.

    Thanks for the flurry of ideas and advice. I’ll be sure to post again in the future on WordPresses own support area to get no support “once again”.

    OK, it only took me 4 days to finally figure this out after hacking my way through core files, changing hooks, overriding filters in the header and reading about 200 wordpress related sites.

    I found the answer and as it annoys me to hell the support here is often bleak, with “help me with…” only to have no replies, I thought it would be good to post my findings for others.

    echo mysql2date('l jS F, Y, g:ia', $comments[$comments_count]->comment_date);

    All I needed to use is the mysql2date() function in my comments.php theme file with whatever PHP date formatting I wanted and voila.

    I should probably point out that $comments_count is my own variable I use to loop the array in a specific manner.

    Thanks. I tried what you suggested, but it doesn’t work. I edited the comments-template.php file in wp-includes and it still gives me the wrong format.

    Thanks for the tip, it helped me a lot!

    Thank you!! This helped me, too.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Changing comment date format when looping $comments array’ is closed to new replies.