I'm trying to count the days since a post was made. SQL saves the date and time in the table pins
in the column time
. The format is 2013-11-20 10:36:01.
I have read up on how to do this on http://www.w3schools.com/sql/func_date_format.asp
and have come up with the following code:
<?php
$dayssince = mysql_query("SELECT DATEDIFF(day,'CURDATE()','$pinDetails->time') AS DiffDate FROM pins WHERE id ='$pinDetails->id'");
?>
<?php echo $dayssince; ?>
Where $pinDetails->time
is the datestamp in the database.
However, nothing shows, not even an error number.
EDIT:
I got it to working using this code:
$result = mysql_query("SELECT DATEDIFF(CURDATE(), '$pinDetails->time')");
$dayssince = mysql_result($result, 0);