Don't show date if no date selected

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

By JeffC - March 9, 2016

I have a section on my website for events.

The code below shows the start and end date of the event. 

How can I amend the code below so that if no date is selected in the cms nothing appears.

In cmbs I have set the default value to None/Blank.

Currently if I do not select a date in the cms the following is displayed: 30 November - 0001

<?php if ($detailRecord['start_date'] || $detailRecord['end_date'] ): ?>
<?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; ?>

Thanks

Jeff

Jeff

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/