PHP 两个日期之间的差异最多只能计算 4 天
直到 2 月 11 日,我一直在使用脚本根据两个日期之间的差异更新数据库,没有出现任何问题。然后突然间奇怪的事情开始发生,而剧本没有做任何改变。
这个想法是更新数据库中最后更新一天前的一些记录,并更新最后更新 7 天前的其他记录。这就是我正在使用的:
$datenew7 = new DateTime("now");
$datenew7->modify("-7 day");
$expirydate7 = $datenew7->format("d/m/Y H:i:s");
$datenew1 = new DateTime("now");
$datenew1->modify("-1 day");
$expirydate1 = $datenew1->format("d/m/Y H:i:s");
$strSQL1="UPDATE vacancies SET dateupdated= #" . date("F j Y g:i a") . "# WHERE jobtype='p' AND dateupdated < #" . $expirydate1 . "#";
$strSQL7="UPDATE vacancies SET dateupdated= #" . date("F j Y g:i a") . "# WHERE jobtype='s' AND active='a' AND dateupdated < #" . $expirydate7 . "#";
第一个查询仍然可以正常工作,但是第二个查询每次运行脚本时都会更新这些记录,无论已经过去了多少天。
有趣的是,如果我将“-7 天”更改为“-4 天”或更少,它就可以正常工作。任何超过“-5 天”的时间都不起作用。
我在这里搜索并找到了一种更简单的获取变量的方法,因此将它们更改为:
$expirydate7 = date('d-m-Y H:i:s', strtotime("-3 day"));
$expirydate1 = date('d-m-Y H:i:s', strtotime("-1 day"));
...但结果仍然相同。我到处寻找但没有快乐。非常感谢任何帮助。
I'd been using a script to update a database based on the difference between two dates without any problem until 11 February. Then all of a sudden strange thihngs started happening without any changes being made to the script.
The idea is to update some records in a database which were last updated one day ago, and update others which were last updated 7 days ago. This is what I was using:
$datenew7 = new DateTime("now");
$datenew7->modify("-7 day");
$expirydate7 = $datenew7->format("d/m/Y H:i:s");
$datenew1 = new DateTime("now");
$datenew1->modify("-1 day");
$expirydate1 = $datenew1->format("d/m/Y H:i:s");
$strSQL1="UPDATE vacancies SET dateupdated= #" . date("F j Y g:i a") . "# WHERE jobtype='p' AND dateupdated < #" . $expirydate1 . "#";
$strSQL7="UPDATE vacancies SET dateupdated= #" . date("F j Y g:i a") . "# WHERE jobtype='s' AND active='a' AND dateupdated < #" . $expirydate7 . "#";
The first query still works fine, but the second query updates those records every time the script is run, regardless of the number of days which have elapsed.
Interestingly, if I change "-7 day" to "-4 day" or less, it works ok. Anything above "-5 day" doesn't work.
I since searched here and found a simpler way to get the variables, so changed them to:
$expirydate7 = date('d-m-Y H:i:s', strtotime("-3 day"));
$expirydate1 = date('d-m-Y H:i:s', strtotime("-1 day"));
...but still the same result. I've searched everywhere but no joy. Any help greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的日期格式是
Ymd H:i:s
。尝试使用该格式并查看它是否有效。The proper date format is
Y-m-d H:i:s
. Try using that format and see if it works.