format("Y-m-d H:i:s"); $date = new DateTime(); $tosub = new DateInterval('PT12H00M'); $halfdayago = $date->sub($tosub); $datehalfdayago = $date->format("Y-m-d H:i:s"); $getschedqry = mysqli_query($link, "SELECT * FROM schedules WHERE assetid = $assetid AND runtime <= '$datenow' AND runtime >= '$datehalfdayago' AND rantime IS NULL ORDER BY runtime ASC LIMIT 1"); while($row = mysqli_fetch_array($getschedqry)){ $schedid = $row['id']; } if(isset($schedid)){ echo "$schedid"; }else{ echo 0; } } }