Hi,
the date format isn’t displaying correctly. In the display format it is set to show like dd/mm/yy
On the front end it’s displayed like this: 12082014
Anything obvious that might be causing this?
The site is in dev at the moment so not live but I can send login if required.
The display format is only applicable when a user selects a date. If you want the date to format in the loop you will have to set the date like so:
<?php $date = new DateTime(get_field('fieldname'));
echo $date->format('n/j/Y'); ?>
Format the date accordingly: http://php.net/manual/en/function.date.php
rockeypjb thanks for that direction above. I have selected an ACF date though when uploading an article in the post admin so shouldn’t it then print in the format I have selected in the display settings?
Using your suggestion above if I enter that as is without changing the filedname I see it prints the current date. I add in my own field name and it stops printing the page at that point (I’ve changed the date format).
<?php $date = new DateTime(get_field(‘published_on’));
echo $date->format(‘d/m/Y’); ?>
What I ideally want is something like the below (but this doesn’t work)
<span>Published on:</span>
<?php $published_on = get_field(‘published_on’);
if ($published_on) {
echo $published_on->format(‘d/m/Y’);
} else {
echo ‘Not known’;
} ?>
Is there something simple I’m doing wrong here?