Everything in my project works perfectly except this. My database table (customerpurchases) has two particular fields: invoicedate and warranty. The invoicedate (type is DATE) column is the date of purchase, the warranty (type is INT) column is the length of the warranty in months.
I'm trying to do two things:
Take the value from warranty and add it to invoicedate. This will get me the warranty deadline. (THIS IS WHERE I AM CURRENTLY STUCK)
Subtract the current date from the warranty deadline to obtain the number of months remaining in the warranty.
I've seen dozens of samples that involve using DATE_ADD. I can make it work when I statically supply a date, expr and unit (ex. ('2007-11-30', INTERVAL 12 MONTH)), but when I replace '2007-11-30' with 'invoicedate' and 12 with 'warranty' it will not work. Any help provided will be deeply appreciated.
Here's a sample of what I've tried (among several variations):
$sql = "SELECT * FROM customerpurchases DATE_ADD('invoicedate', INTERVAL 'warranty' MONTH) WHERE serial = '$searchserial'";
$result_sql = mysql_query($sql) or die(mysql_error());
echo $result_sql;