Compare MYSQL DATETIME function in PHP
In the MySql database I have two columns, start_date and end_date they are both DATETIME functions so they store both the date and the time
In the sites page I'm displaying the start date, the start time and end time + plus the end date. BUT what I want to do is only show the end date when it's different from the start date like this
Date: 24 Sep 2010
Time: 7:30 pm - 10:00 pm (this being a one day event)
OR
Date: 24 Sep 2010 - 29 Sep 2010
Time: 7:30 pm - 10:00 pm (this being a multi-day event)
My current code is:
Date: <?php echo date('j M Y',strtotime ($row_rsCiviEventResults['start_date'])); ?>
<?php if ($row_rsCiviEventResults['end_date']!=""){ ?>
- <?php echo date('j M Y',strtotime ($row_rsCiviEventResults['end_date'])); ?>
<?php } ?>
So if the end_ date datetime is empty it doesn't show it. However if I add a second criteria of saying "OR if the end_date is not the same at the start_date, then don't show it either"
Date: <?php echo date('j M Y',strtotime ($row_rsCiviEventResults['start_date'])); ?>
<?php if ($row_rsCiviEventResults['end_date']!="" || $row_rsCiviEventResults['end_date'] != $row_rsCiviEventResults['start_date'] ){ ?>
- <?php echo date('j M Y',strtotime ($row_rsCiviEventResults['end_date'])); ?>
<?php } ?>
Now this didn't work but then I realised that the end_date would always differ from the start_date because it also stores the time. "2010-09-01 09:00:00" compared to "2010-09-01 15:00:00" for example.
So that was a long winded way of asking, how do I compare just the date and not the time part of the DATETIME function in the PHP code.
I should add that this MySQL database is part of a third party application called civiCRM so I am unable to alter the database.
The page in question is here. In this case the second date should show as the event runs for more than one day but on this page it should NOT show as the date is identical (but the time is not of course).