Home › Forums › General Issues › Date not showing up
I am not sure what I have wrong here but it is something because the date will not show up on the events category but will show up on any other category. I have it set I thought that if the get_field is empty use the else statement so the older events posts not using the ACF will still show their date.
Here is my code:
<?php if (is_single() && has_category('events')) { ?>
<?php if(get_field('event_starts') && get_field('event_starts') !="") { ?>
<div class="e-date"><span class="e-bold">Date: </span>
<?php $lastDate = ''; $date = DateTime::createFromFormat('Ymd', get_field('event_starts'));
if ($date != $lastDate) {
$lastDate = $date;
echo $date->format('F d, Y');
} ?>
<?php } ?>
<?php } else { ?>
<span class="datetime"><?php the_time('F j, Y'); ?></span>
<?php } ?>
Hi @justawebbie
I had the same problem with echoing the date values.
Which PHP version you are working on?
Try using “date() and “strtotime()””..
<?php
echo date('F d, Y', strtotime( get_field('event_starts') );
?>
.. instead of “DateTime”.
Hope this will solved your problem.
Thank you so much for your help. I tried that and it is throwing a syntax error and my knowledge is at a beginner level in trying to figure out what is wrong.

Hi @justawebbie
It would be best to share the syntax error that you are receiving when using the code so that we can be able to help you further.
It is most likely a typo or something on your end.
The topic ‘Date not showing up’ is closed to new replies.
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.