0

I am trying to retrieve my 2 dates (start date and end date) and to get the difference between them in the same format in wordpress.

My ACF DatePicker fields return: j F, Y format that is 20 september, 2021

I tried with the ACF method , but it gives me an error..

    $start_date = get_field('start_date');
    $date = DateTime::createFromFormat('j F, Y', $start_date);
    echo $date->format('j F, Y');

   Uncaught Error: Call to a member function format() on bool

Why it doesn't work ?

Robert Crx
  • 13
  • 2

1 Answers1

0

It’s possible the return type is not set correctly for the ACF ‘start_time’ field. Might be worth checking this in the custom fields settings.

The other thing you can try is wrapping the get_field(“start_time”) in a strtotime() function before passing it to the formatted.

See this for an idea. https://stackoverflow.com/a/6239010/4172254

Omar
  • 332
  • 2
  • 9