PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
It looks like your `info` field is in the MySQL Date format. If so, you can easily use the MySQL DATEDIFF function function to do the calculation right in MySQL.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Check the documentation on the link I sent. It shows how you can use the DATEDIFF function. One of your parameters to the DATEDIFF function in your query can be your `info` column. The other parameter can be a string you provide that is your second, manually created date.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
$q = mysql_query("SELECT DATEDIFF (date1, date_added) FROM listings") or die(mysql_error());
$info = mysql_fetch_array($q, MYSQL_ASSOC);
@mysql_free_result($q);
$date1=date('Y-m-d'); //todays date
$date2=$info['date_added']; //date in field for record
echo (round($diff=strtotime($date1)-strtotime($date2)))/86400;
When i echo this it needs to give the days between each date in database and current date.