Page 1 of 1

Comparing dates - doesn't seem to work

Posted: Fri Jan 23, 2009 7:17 am
by mattpointblank
Hi all,

I'm looping through a result set of events. I want to restrict events that have already happened from appearing in the output. I can't do this in my SQL query because some of the events have StartDate and EndDate fields, others have just StartDates, so I can't select all the events that start in the past and end in the future.

Anyway, here's my code (simplified):

Code: Select all

 
$today = date("Y-m-d H:i:s");
$compStartDate = strtotime($StartDate);
$compToday = strtotime($today);
 
if($compStartDate >= $compToday) {
 
  // output event info here
 
}
 
$StartDate is a result from my database, and has the same date structure as $today.

The code doesn't work though - it outputs nothing. I'm confident it's not down to me echoing out the results elsewhere, so the logic of the loop is wrong. Any ideas?

Re: Comparing dates - doesn't seem to work

Posted: Fri Jan 23, 2009 7:29 am
by VladSun
mattpointblank wrote:Hi all,

I'm looping through a result set of events. I want to restrict events that have already happened from appearing in the output. I can't do this in my SQL query because some of the events have StartDate and EndDate fields, others have just StartDates, so I can't select all the events that start in the past and end in the future.

Anyway, here's my code (simplified):

Code: Select all

 
$today = date("Y-m-d H:i:s");
$compStartDate = strtotime($StartDate);
$compToday = strtotime($today);
 
if($compStartDate >= $compToday) {
 
  // output event info here
 
}
 
$StartDate is a result from my database, and has the same date structure as $today.

The code doesn't work though - it outputs nothing. I'm confident it's not down to me echoing out the results elsewhere, so the logic of the loop is wrong. Any ideas?
Yes - debug:

Code: Select all

 
$today = date("Y-m-d H:i:s");
$compStartDate = strtotime($StartDate);
$compToday = strtotime($today);
 
echo $today."<br />";
echo $StartDate."<br />";
echo $compStartDate."<br />";
echo $compToday."<br />";