I'm pulling a row from a database and there is a date field (y-m-d). I need to create an if statement so that I can do something IF that date is longer then 13 days ago. I've already found out how to display all results which are longer then 13 days ago if it is any help.
我从数据库中拉出一行,并且有一个日期字段(y-m-d)。我需要创建一个if语句,以便我可以做一些事情,因为该日期比13天前更长。如果有任何帮助的话,我已经找到了如何显示超过13天前的所有结果。
SELECT * FROM links WHERE (TO_DAYS(NOW()) - TO_DAYS(date))>13
Any help would be greatly appreciated.
任何帮助将不胜感激。
3 个解决方案
#1
In php you can use:
在PHP中你可以使用:
$date = '2008-11-05';
if (strtotime("now") > strtotime("+13 days", strtotime($date))) {
//Do something
}
#2
One way is to convert the y-m-d string to a timestamp, and see if it is larger than 13*86400 seconds old (86400 = no of seconds in a day)
一种方法是将y-m-d字符串转换为时间戳,并查看它是否大于13 * 86400秒(86400 =一天中没有秒)
$age=time() - strtotime($date);
if ($age > (13*86400))
{
//do something
}
#3
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(或类似的你的风味),你会得到一个额外的列,其日期差异称为“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”]。
#1
In php you can use:
在PHP中你可以使用:
$date = '2008-11-05';
if (strtotime("now") > strtotime("+13 days", strtotime($date))) {
//Do something
}
#2
One way is to convert the y-m-d string to a timestamp, and see if it is larger than 13*86400 seconds old (86400 = no of seconds in a day)
一种方法是将y-m-d字符串转换为时间戳,并查看它是否大于13 * 86400秒(86400 =一天中没有秒)
$age=time() - strtotime($date);
if ($age > (13*86400))
{
//do something
}
#3
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(或类似的你的风味),你会得到一个额外的列,其日期差异称为“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”]。