Hello all, I have the following code, and it doesn’t seem to be working. It’s taken WAY LONGER than I intended, and I wanted to see if anyone with more experience can help.
My DB has an alternative hours start time of 11am and ends at midnight. I can’t tell if my code straight up doesn’t work, or if midnight (00:00:00) is causing problems, since nothing can be LESS THAN 00:00:00. It shouldn’t be a problem, though, once converted into a UNIX timestamp…hmmm…
I’ve tried manipulating midnight, but am not sure if subtracting one second is sufficient, or assigning another value, or if there’s simply a comparison in php I can use that accounts for time comparisons. PLEASE help me with an efficient practice, or with my code if it’s simply off. Thanks in advance.
[php]//if alt hours has exists (has an id)
//get name, start time and end time from db
$sqli = $conn->prepare(‘SELECT alt_hr_name,DATE_FORMAT(alternative_hrs.alt_hr_start, “%H:%i:%S”),DATE_FORMAT(alternative_hrs.alt_hr_end,"%H:%i:%S") FROM alternative_hrs WHERE alt_hrs_id = ?’);
$sqli->bind_param(‘i’,$alt_hrs_id);
$sqli->execute();
//get alt_hours start/end times
$sqli->bind_result($hour_name,$hour_start,$hour_end);
while($sqli->fetch()) {
//compare time to now …all these echo outputs, so I know it’s grabbing data
$cur_time = strtotime(“now”);
$alternative_hour_start = strtotime($hour_start);
$alternative_hour_end = strtotime($hour_end);
if($cur_time >= $alternative_hour_start && $cur_time < $alternative_hour_end) {
//apply alternative hour code
echo “It’s works!”;
}
else {
//get regular hours code
echo “It’s broken!”;
}
[/php]
It’s currently 6pm, so $alternative_hours should be active. But, I keep getting, “It’s broken!”. Please help.