I am trying to insert a future date into a MySQL table from PHP. I have been able to insert the current date using strtotime but when I add time to this call it does not seem to insert it. Here is the code:
<?php
$currentDate = strtotime('now');
$expirationDate = strtotime('+ 90 days');
include_once "mysql-connect.php";
$cur = "UPDATE table SET current_date = FROM_UNIXTIME($currentDate) WHERE ...";
if (!mysql_query($cur,$con))
{
die('Heres Your Error: ' . mysql_error());
}
echo "the date is set";
$exp = "UPDATE table SET expiration_date = FROM_UNIXTIME($expirationDate)
WHERE ...";
if (!mysql_query($exp,$con))
{
die('Heres Your Error: ' . mysql_error());
}
echo " expiration date is set";
mysql_close($con)
?>
Like I said, when I run this it will insert the current date into the current_date row as requested. For some reason it will not insert expiration_date which is 90 days in front of the current date. I have verified that the expiration date is being picked up as 90 days in the future. Why is this not working?
You can do it in MySQL directly:
which’ll save you the excess round-tripping from datetime->unix timestamp->datetime.