I calculated the elapsed time and I want to echo it with red font if it's longer than 24 hours. This works if its 24:00:00 but if it turns 25:00:00 it doesn't echo it in red anymore.
How can I fix this ?
This is what I have done:
- I take the timestamp from the Status table, this is in timestamp format.
- Then I get the current time from the database.
- I do strtotime() for both values to assure they have the same format.
- I subtract the Status time from current time so I get the elapsed time.
-
Then I check if the elapsed time is bigger than 24 hours.
$timestamp = $status_row['Time']; $sql_time_difference = "SELECT TIMEDIFF(NOW(), '$timestamp') as TimeDiff"; //echo $sql_time_difference; $time_select = mysqli_query($conn, $sql_time_difference); $time_row = mysqli_fetch_assoc($time_select); $time_difference = $time_row['TimeDiff']; //echo $time_difference.'<br>'; $time1 = strtotime($time_difference); $time2 = strtotime('24:00:00'); if ($time_difference >= $time2){ echo '<b><font color="red">'.$time_difference.'</font></b>'; } else { echo $time_difference; }
Aucun commentaire:
Enregistrer un commentaire