每次点击密码重置req链接时,我都会使用now()
PHP函数将时间存储到用户表格中:
2015-06-15 12:02:09
如果超过2小时,我如何检查格式的日期和时间?一个简单的2*60*60
会有帮助吗?
日期也要考虑。如果他们在指定时间之后一天点击链接怎么办?
答案 0 :(得分:1)
mysql有自己的一组日期函数
SELECT pasword_link_stuff from table where (NOW() - INTERVAL 2 HOUR) < date_field
答案 1 :(得分:1)
strtotime()
就是你要找的东西。看看你尝试过的代码会很有帮助。
<?php
$timediff = strtotime('now') - strtotime('2015-06-15 00:02:09'); // in seconds
if( $timediff > 7200 ) { // 7200 seconds is 2 hours
// do stuff;
}
?>
这会将您的日期考虑在内,因为strtotime
函数会返回自纪元时间(1970年1月1日)以来经过的秒数。
答案 2 :(得分:0)
你可以做点什么,
select * from table where (time_to_sec(timediff('2015-06-15 12:02:09', CURRENT_TIMESTAMP )) / 3600) > 2