Whats the way to format a date after using get_posts()

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?

1 Answer
1

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

Leave a Comment