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?


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);

  • 1
    +1 for mysql2date(), it's how get_the_date() does it internally. – Rarst Feb 20 '11 at 11:25
  • 4
    <?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

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.