These are the inputs an database rows
$current 2012-07-26 15:30:00
1st $row['start'] 2012-07-26 14:00:00
2nd $row['start'] 2012-07-26 17:00:00
When I run the following code with the above current time, I get correctly the “Starts soon” for the 2nd row, but also I get it mistakenly on the 2nd row that it already started.
How do I edit this code to return me the “Starts soon” message only to the rows that will start in the next two hours?
$diff = strtotime($row['start']) - strtotime($current);
if ($diff < 7200) {
echo 'Starts soon';
} else if ($diff <= 0) {
echo 'Started';
} else {
echo 'Starts';
}
All
$diffmatching your secondifclause (< 0) are already caught by the firstifclause (< 7200) and never reach the secondifin thatelseclause.As a solution, restructure your code in the following way:
EDIT
With respect to the question in comments:
If you mean the calendar day, you could use the following code:
If you mean just that both times are no more than 24 hours apart, use