Support

Account

Home Forums ACF PRO Get date or time from the Date & Time Picker field Reply To: Get date or time from the Date & Time Picker field

  • Hi @huwrowlands

    The best way to get only the date or the time is by converting the value to a date object like this:

    $date = get_field('date_time_picker', 85, false);
    $date = DateTime::createFromFormat('Y-m-d H:i:s', $date);
    
    echo $date->format('Y-m-d');
    echo "\n";
    echo $date->format('H:i:s');

    Please check this page to see the available format: http://php.net/manual/en/function.date.php.

    I’m afraid you need to query it as whole date and time. If you need to query it separately, you need to create separate fields for the date and the time.

    I hope this makes sense 🙂