简体   繁体   English

PHP如果日期前> 13天

[英]PHP If Date Is >13 Days Ago

I'm pulling a row from a database and there is a date field (ymd). 我从数据库中拉出一行,并且有一个日期字段(ymd)。 I need to create an if statement so that I can do something IF that date is longer then 13 days ago. 我需要创建一个if语句,以便如果日期长于13天之前可以执行某些操作。 I've already found out how to display all results which are longer then 13 days ago if it is any help. 我已经找到了如何显示比13天前更长的所有结果(如果有帮助的话)。

SELECT * FROM links WHERE (TO_DAYS(NOW()) - TO_DAYS(date))>13

Any help would be greatly appreciated. 任何帮助将不胜感激。

In php you can use: 在php中,您可以使用:

$date = '2008-11-05';
if (strtotime("now") > strtotime("+13 days", strtotime($date))) {
  //Do something
}

One way is to convert the ymd string to a timestamp, and see if it is larger than 13*86400 seconds old (86400 = no of seconds in a day) 一种方法是将ymd字符串转换为时间戳,并查看它是否大于13 * 86400秒旧(86400 =一天中没有秒)

$age=time() - strtotime($date);
if ($age > (13*86400))
{
     //do something
}

You haven't given us a whole lot to go on, but if you use the following SQL (or equivalent for your flavor), you'll get an additional column with the date difference called "days_diff": 您还没有给我们太多帮助,但是,如果使用以下SQL(或与您的风格等效的SQL),则会获得日期差为“ days_diff”的附加列:

SELECT *, DATEDIFF(datecolumn,CURDATE()) AS days_diff FROM links

Then you can access $row["days_diff"] in your PHP. 然后,您可以在PHP中访问$row["days_diff"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM