PHP 7天后删除记录?
我想从数据库中删除 7 天或更早的记录。我将服务器时间设置为英国时间,但由于某种原因,我在下面编写的代码总是回显帐户已删除 7 天或以上,并且由于某种原因它无法正常工作。在对测试数据库进行测试之前,我决定暂时使用简单的 echo,但正如我所说,它不起作用。
有人有任何建议为什么它不起作用吗?我一定是做错了什么。
<?php
// Get Current Time
$current_time = time();
/* The time i used below (unix) for testing is
18-02-2011 14:34:24 (yesterdays date/time) */
$account_delete = strtotime(time('1298039664'));
if ($current_time - $account_delete >= (7*24*60*60)){
echo 'Account Deleted as 7 or more days old';
} else {
echo 'Account Not Deleted as less than 7 days old';
}
?>
I want to delete records from a database when they are 7 days or older. I have my server time set to UK time but for some reason the code I wrote below always echo's Account Deleted as 7 or more days old and for some reason it's not working. Before I test on my test database I decided to use a simple echo for now, but as I say it won't work.
Anyone have any suggestions why it's not working? I must be doing something wrong.
<?php
// Get Current Time
$current_time = time();
/* The time i used below (unix) for testing is
18-02-2011 14:34:24 (yesterdays date/time) */
$account_delete = strtotime(time('1298039664'));
if ($current_time - $account_delete >= (7*24*60*60)){
echo 'Account Deleted as 7 or more days old';
} else {
echo 'Account Not Deleted as less than 7 days old';
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
strtotime(time('1298039664'))
替换为1298039664
?time() 不带任何参数。
Replace
strtotime(time('1298039664'))
with1298039664
?time() does not take any parameters.