Forum Moderators: coopster
$result=mysql_query("SELECT *, UNIX_TIMESTAMP(Date_Field) As UnixDate FROM mytable ");
$row=mysql_fetch_array($result);
$olddate=$row[UnixDate];
$newdate=$olddate+((60*60)*24)*45) // i.e. add total number of seconds in 45 days
then reinsert it into the dbase
$newdate=date('Y-m-d',$newdate); // converts unixdate back to mysql format
$sql=mysql_query("UPDATE mytable SET Date_Field='$newdate' ");
hope that helps,
hughie
UPDATE table SET newfield = oldfield + INTERVAL '45 days';
I think there's a similar syntax in MySQL...
;)
I was able to do this to generate the necessary display on the page:
$today = strtotime("now");
$month = date('m',$today);
$day = date('d',$today);
$year = date('y',$today);
$date_today = date('m/d/y',$today);
$expire_date = mktime(0, 0, 0, $month, $day + 45, $year);
Seems like a nice thought and more importantly, it's working for displaying the date on the page. But my problem now is in the updating of the database record.
If I do:
$query = "INSERT INTO $table_to_use (field1, field2, date_applied, expire_date, status) VALUES ('$var1', '$var2', '$date_today', '$expire_date', '$status')";
Assuming that the date today is Aug. 1, 2005, what gets written on the field is:
-- for date_applied, it's 2008-01-05
-- for expire_date, it's 0000-00-00.
Why is this so?
Thanks again for the help.