Hello all. My database holds date, start and end variables. In my code I grab the start and them as the user selects them, and convert them to timestamps like so (all inside a foreach loop)..
$selectionDate = strtotime($timeQry['date']);
$startTimes[] = strtotime($timeQry['start'],$selectionDate);
$endTimes[] = strtotime($timeQry['end'],$selectionDate);
This gives me the correct start and end times as timestamps. I then have a logic statement to validate it and see if any of the selected times overlap....
if(($startTimes[1] < $startTimes[0]) && ($endTimes[1] > $startTimes[0]) ||
($startTimes[1] > $startTimes[0]) && ($startTimes[1] < $endTimes[0]) )
{
echo "overlap"
}
This works fine most of the time, however if one of the end times if after 12 midnight (say 02:00am), then that time stamp will be smaller than the start time because the code uses the date the booking would start on. This causes the logic to fail and the overlap is missed.
I have thought about doing:
if( ($endTimes[$k] >= $selectionDate) )
{
$endTimes[] = strtotime($timeQry['end'],$newDate+ 1253574000);
}
else
{
$endTimes[] = strtotime($timeQry['end'],$selectionDate);
}
//...run same logic query
Which creates a new date which is a day later. But I don't think this is the right way to go about it. If anyone can help me out I would be most grateful. It's got me scratching my head a bit this one! Many thanks