WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I see that theres no way to get a formatted date from a function like

echo get_the_date($post->ID, 'd M Y');

get_the_date only works with the current $post. If I used get_posts() how can I format the date. With pure PHP I can do something like ...

echo DateTime::createFromFormat('Y-m-d h:i:s', $cp->post_date)->format('d M Y');

but its abit long, and I don't know if there's a need to actually create a DateTime object, perhaps its a waste of resources?

share|improve this question
up vote 7 down vote accepted

echo date('Y-m-d h:i:s', strtotime($cp->post_date)); ... or better use the wordpress functionado echo mysql2date('Y-m-d h:i:s', $cp->post_date);

share|improve this answer
+1 for mysql2date(), it's how get_the_date() does it internally. – Rarst Feb 20 '11 at 11:25
<?php echo mysql2date( get_option('date_format'), $cp->post_date ); ?> to use the configuration date set in wordpress admin – Tribalpixel Jul 30 '12 at 21:30
@Tribalpixel Perfect solution, thanks! – Markus Amalthea Magnuson May 25 '14 at 20:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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