I have been working on a WP site and i wanted to add a date for a template. I set up ACF and added a date field to the template and it works but i need my date to be displayed like this: l j F Y. Instead of :dd/mm/yy.

I have tried the recommended way that is on the ACF documentation wich looks like this:

$date = get_field('date', false, false);
$date = new DateTime($date);
echo $date->format('l j F Y');

But for some reason this just does not work and disables the rest of the code underneath it.

closed as off-topic by Mark Kaplun, Nathan Johnson, Dave Romsey, Michael, Christine Cooper Feb 27 '18 at 11:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.


*  Create PHP DateTime object from Date Piker Value
*  this example expects the value to be saved in the format: yymmdd (JS) = Ymd (PHP)

$format_in = 'Ymd'; // the format your value is saved in (set in the field options)
$format_out = 'd-m-Y'; // the format you want to end up with

$date = DateTime::createFromFormat($format_in, get_field('date_picker'));

echo $date->format( $format_out );

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