我有一个带有时间列的表格。
CREATE TABLE `mbusGuestCodeExpires` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`hashOfUser` int(11) NOT NULL,
`expiresTime` time DEFAULT NULL,
`active` int(1) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `hashOfUser` (`hashOfUser`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 PACK_KEYS=0;
和具有此字段值的输入,用户可以更改它,其中$expireTime
是表中的时间和$timeDiffHour
,$timeDiffMinute
是表中剩余时间。
echo "<div class='expires'>Expires:<input type='text' class='expiresTime' value='{$expireTime}'/></div><div class='left'>";
if (($timeDiffHour>=0) && ($timeDiffMinute>0))
{
echo"Left:".$timeDiffHour."h. ".$timeDiffMinute." min.";
}
echo"</div>";
我现在需要在$expireTime
时间将活动字段更改为 0。除了每分钟运行一次 cron 脚本来检查所有列并在当前时间较少时检查其值之外,最好的方法是什么?
怎么样:
select ... where expiresTime < curtime()
文档参考: http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_curtime