close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Compare MYSQL DATETIME function in PHP

Thread began 9/22/2010 10:22 am by John Langer | Last modified 9/22/2010 12:59 pm by John Langer | 3111 views | 9 replies

John LangerBeta Tester

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)


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

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...