Home Forums General Issues Date not showing up


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()””..

    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.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Date not showing up’ is closed to new replies.