Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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

Your Answer

 
discard

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.