Using if statement to hide date content

3 posts by 2 authors in: Forums > CMS Builder
Last Post: September 19, 2014   (RSS)

Sure, this is how I'd do it:

<?php
$startdate = date("j F Y", strtotime($article['event_starts']));
$enddate = date("j F Y", strtotime($article['event_finish']));
if($startdate != $enddate) : ?>
<p><?php echo $startdate ?> - <?php echo $enddate ?></p>
<?php else : ?>
<p><?php echo $startdate ?></p>
<?php endif; ?>

--------------------

Claire Ryan
interactivetools.com

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

By JeffC - September 19, 2014 - edited: September 19, 2014

Thank you.

I took your solution one stage further. 

<?php
$startdate = date("j F Y", strtotime($article['event_starts']));
$startdateabb = date("j", strtotime($article['event_starts']));
$enddate = date("j F Y", strtotime($article['event_finish']));
if($startdate != $enddate) : ?>
<p><?php echo $startdateabb ?> - <?php echo $enddate ?></p>
<?php else : ?><p><?php echo $startdate ?></p>
<?php endif; ?>

The resulting output looks like this if it is a one-day event: 19 September 2014

If it is an event that runs over two or more days it looks like this: 19 - 20 September 2014 

Jeff