简体   繁体   中英

PHP If Date Is >13 Days Ago

I'm pulling a row from a database and there is a date field (ymd). 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.

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

Any help would be greatly appreciated.

In php you can use:

$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)

$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":

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

Then you can access $row["days_diff"] in your PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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