gpt4 book ai didi

php - 如何查看相对日期?

转载 作者:行者123 更新时间:2023-11-29 06:04:27 26 4
gpt4 key购买 nike

我正在编写密码恢复代码,该代码使用以 date("Y-m-d H:i:s") 格式存储的 token 和日期,例如2012-09-06 18:59:53。我使用下面的代码来检查用户 ID 的 token key 是否存在:

$sql = mysql_query("SELECT * FROM `recoveryemails` WHERE `UserID` = '$uid' and `Key` = '$key' and `expDate` >= '$curDate'");

我需要在检索 expDate 后添加另一个条件,以使用 PHP 检查它是否早于 3 天。谁能帮我解决这个 PHP 代码吗?

最佳答案

在 MySQL 中要简单得多:WHERE ... AND expdate >= DATE_SUB(NOW(),INTERVAL 3 DAY)

但是如果您坚持使用 PHP 进行操作,您将需要:

$threedaysago = strtotime("-3 days");
$expdate = strtotime($row['expDate']);
if( $expdate >= $threedaysago) { /* more recent than three days ago */ }

关于php - 如何查看相对日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12254305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com