Home Forums General Issues Echo date picker field returns fatal error Reply To: Echo date picker field returns fatal error

  • Well I finally solved it by changing the store format to yymmdd. After that I could use the code example from the documentation like this.

    $date = DateTime::createFromFormat('Ymd', get_field('date_picker'));
    echo $date->format('d-m-Y');

    I changed the output value to j F Y but then found out that the output was English even though it was displayed in Dutch in the WP admin area. But well that was easily sorted with the translation snipper from the documentation.

    $dateformatstring = "l d F, Y";
    $unixtimestamp = strtotime(get_field('date_picker'));
    echo date_i18n($dateformatstring, $unixtimestamp);

    So in the end I didn’t even have to use my code that was causing the error and was making it too complicated for myself when I could use the code examples. But well, I learned something again as this was my first usage of the date picker field.