Don't show date if no date selected

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 9, 2016   (RSS)

By Damon - March 9, 2016

Hi Jeff,

Try this code:

 <?php  if(($detailRecord['start_date'] != '0000-00-00 00:00:00') && ($detailRecord['end_date'] != '0000-00-00 00:00:00')): ?>
         Date fields are NOT blank!
         ....add code to display dates.....
<?php endif; ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By JeffC - March 9, 2016 - edited: March 9, 2016

Perfect, thank you.

I just made one small amend, shown in red: changed end_date to finish_date. 

This was a mistake in my original code, just highlighting should anyone else be following this thread.

<?php  if(($detailRecord['start_date'] != '0000-00-00 00:00:00') && ($detailRecord['end_date'] != '0000-00-00 00:00:00')): ?>
<?php $startdate = date("j F Y", strtotime($detailRecord['start_date'])); $startdateabb = date("j", strtotime($detailRecord['start_date'])); $enddate = date("j F Y", strtotime($detailRecord['finish_date'])); if($startdate != $enddate) : ?>
<p class="lead"><time itemprop="startDate" datetime="<?php echo $startdateabb ?>"> <?php echo $startdateabb ?></time> - <time itemprop="endDate" datetime="<?php echo $enddate ?>"><?php echo $enddate ?> </time>
</p>
<?php else : ?>
<p class="lead"><?php echo $startdate ?></p>
<?php endif; ?>
<?php endif; ?>

Jeff