Title: Changing comment date format when looping $comments array
Last modified: August 19, 2016

---

# Changing comment date format when looping $comments array

 *  Resolved [greg2008](https://wordpress.org/support/users/greg2008/)
 * (@greg2008)
 * [17 years ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/)
 * 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

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [17 years ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/#post-1082699)
 * Use PHP’s [date()](http://uk2.php.net/manual/en/function.date.php) function.
 *  Thread Starter [greg2008](https://wordpress.org/support/users/greg2008/)
 * (@greg2008)
 * [17 years ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/#post-1082706)
 * 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.
 *  Thread Starter [greg2008](https://wordpress.org/support/users/greg2008/)
 * (@greg2008)
 * [17 years ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/#post-1082769)
 * 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”.
 *  Thread Starter [greg2008](https://wordpress.org/support/users/greg2008/)
 * (@greg2008)
 * [17 years ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/#post-1082839)
 * 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.
 *  Thread Starter [greg2008](https://wordpress.org/support/users/greg2008/)
 * (@greg2008)
 * [17 years ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/#post-1082840)
 * I should probably point out that $comments_count is my own variable I use to 
   loop the array in a specific manner.
 *  [honzapokorny](https://wordpress.org/support/users/honzapokorny/)
 * (@honzapokorny)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/#post-1082867)
 * 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.
 *  [bbx](https://wordpress.org/support/users/boomybx/)
 * (@boomybx)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/#post-1082879)
 * Thanks for the tip, it helped me a lot!
 *  [sef125](https://wordpress.org/support/users/sef125/)
 * (@sef125)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/#post-1082906)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 5 participants
 * Last reply from: [sef125](https://wordpress.org/support/users/sef125/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/changing-comment-date-format-when-looping-comments-array/#post-1082906)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
