I have created a timer that will stopped at 4:20 am/pm till 4:29 am/pm The main problem I am having is when the time will be greater then 4 or less then 17 how i will set a logic there I am pretty much confused I tried a logic but this is not working for me the time is not showing then. Like if hours will be greater then 12 like 12 13 14 then how will i get the time difference or when the timer will resume at 16:29 how will i get the difference from 16:29 to 4:20 ??
<?php
require('../config/connection.php');
$last_time = $_POST['time_last'];
$cr_time = $_POST['cr_time'];
$cur_time = explode(':', $cr_time);
$last_time--;
$minutes = array('20', '21', '22', '23', '24', '25', '26', '27', '28', '29');
if($cur_time[0] == '4' || $cur_time[0] == '16') {
if(in_array($cur_time[1], $minutes)) {
$update = mysqli_query($connection, "UPDATE timer SET time_start = '0' WHERE id = '1'");
echo '0';
} else {
$update = mysqli_query($connection, "UPDATE timer SET time_start = '0' WHERE id = '1'");
echo '0';
}
} else {
if($cur_time[0] > '4' || $cur_time[0] < '17') {
$differenceInhour = strtotime('16:20:00') - strtotime($cr_time);
}
if($cur_time[0] >= '17' || $cur_time[0] <= '23') {
$differenceInhour = strtotime('23:59:00') + 14400 - strtotime($cr_time);
}
if($cur_time[0] > '23' || $cur_time[0] <= '4') {
$differenceInhour = strtotime('4:20:00') - strtotime($cr_time);
}
$update = mysqli_query($connection, "UPDATE timer SET time_start = '$differenceInhour' WHERE id = '1'");
echo $differenceInhour;
}
?>
Please help me out with this please I am only having issue when the clock will be greater then 4 how wil i now calculate the remaining time till 16 and from 16 to 4