$query="select TIMEDIFF(date_and_time,NOW()) as time_remaining from exam_schedule";//query to get remaining time from database
if($remaining_time>0)
//run script
else
redirect to another page
if((int)$remaing_time>0)
//run script
else
redirect to another page
if($remaing_time>strtotime('00:00:00'))
//run script
else
redirect to another page
if($remaing_time>mktime(0,0,0))
//run script
else
redirect to another page
我从数据库中获取$remaing_time
。它的差异为b / w(当前和存储时间),即stored_time=10:30
,current_time 10:20
,remaining_time=00:00:10
答案 0 :(得分:1)
使用TIME_TO_SEC将HH:MM:SS
字符串转换为秒。
SELECT TIME_TO_SEC(TIMEDIFF(date_and_time,NOW())) AS time_remaining FROM exam_schedule
然后做
if ($remaining_time > 0)
答案 1 :(得分:1)
我需要的只是
$remaining_time > "00:00:00"
因为$remaining_time
是字符串类型变量。