Home › Forums › Front-end Issues › Date format is wrong › Reply To: Date format is wrong
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?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.