tags:

views:

152

answers:

3

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.

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

Any help would be greatly appreciated.

+1  A: 

In php you can use:

$date = '2008-11-05';
if (strtotime("now") > strtotime("+13 days", strtotime($date))) {
  //Do something
}
Brian Fisher
It's bad practice to mix timestamps from different servers. So stick with php time or database time. If your going to use more than one server.
gradbot
A: 

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)

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

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.

lc