[英]How to check if the time stored in database exceeded two hours
每次單擊密碼重置請求鏈接時,我都會使用now()
PHPfunction以以下形式將時間存儲到用戶表中:
2015-06-15 12:02:09
如果日期和時間超過2小時,如何查看日期和時間的格式? 簡單的2*60*60
幫助嗎?
日期也要考慮在內。如果他們在指定時間之后和之前單擊鏈接,該怎么辦?
mysql有自己的日期功能集
SELECT pasword_link_stuff from table where (NOW() - INTERVAL 2 HOUR) < date_field
如果要使用PHP,則需要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日)以來經過的時間(以秒為單位)。
你可以做類似的事情,
select * from table where (time_to_sec(timediff('2015-06-15 12:02:09', CURRENT_TIMESTAMP )) / 3600) > 2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.