I have a date variable stored in a MySQL database that is formatted as "2012-06-13." I want to use PHP to calculate three days into the future. I have tried experimenting with functions and formulas I found in the manual, but I seem to be missing something. They all break the code on my page.
Can someone please help me calculate the future date using these two variables?
If you're using mySQL, don't calculate by PHP, calculate by mySQL using date and time functions [dev.mysql.com]. You'll likely want to do this very same thing in relation to existing records at some point, for example, a download link that expires three days after a purchase. Both examples below.
$query = "select date_add(curdate(), interval 3 day)"; $result = mysql_query($query) or die("Cannot get future date"); $row = mysql_fetch_array($result); echo $row;
$query = "select date_add(purchase_date, interval 3 day) from customer_purchases where customer_id=$cust_id"; $result = mysql_query($query) or die("Cannot get customer's expiration date"); $row = mysql_fetch_array($result); echo $row;