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

1 Answer 1


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');
  • Thanks ! But it displays 01 value every time.
    – Garrosh
    Nov 13, 2017 at 11:52
  • What do you mean? this should display the day (01-31) depending on the meta field event_start_date. So this for the same $post->ID will always display the same value. Nov 13, 2017 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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