I've a custom field for a date, written like: yyyy-mm-dd
How can I extract only the day to display in PHP ? For the moment, I display the full date:'. get_post_meta($post->ID, 'event_start_date', true).'
Thank you :)
You can try the date() function:
$date = get_post_meta($post->ID, 'event_start_date', true);
$day = date('d', strtotime($date)); //01-31
Another way will be DateTime:
$date = get_post_meta($post->ID, 'event_start_date', true);
$date = DateTime::createFromFormat('Y-m-d', $date);
$day = $date->format('d');
event_start_date
. So this for the same $post->ID
will always display the same value.
Commented
Nov 13, 2017 at 11:54