WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Changing comment date format when looping $comments array (9 posts)

  1. greg2008
    Member
    Posted 5 years ago #

    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?

    Cheers

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Use PHP's date() function.

  3. greg2008
    Member
    Posted 5 years ago #

    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.

  4. greg2008
    Member
    Posted 5 years ago #

    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".

  5. greg2008
    Member
    Posted 5 years ago #

    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.

  6. greg2008
    Member
    Posted 5 years ago #

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

  7. honzapokorny
    Member
    Posted 5 years ago #

    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.

  8. bbx
    Member
    Posted 4 years ago #

    Thanks for the tip, it helped me a lot!

  9. sef125
    Member
    Posted 4 years ago #

    Thank you!! This helped me, too.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.