debuitls Posted August 24, 2009 Share Posted August 24, 2009 Hello all, I'm trying to add 24 hours to the current time and save it in a mysql database. So far I have the following <? $timestamp = time () ; $timestamp1 = $timestamp + 24 * 60 * 60; ?> <? (database connection)... $sql="INSERT INTO proposal (tomorrowtime) VALUES ('$timestamp1')"; ?> This is just returning all 0's in the tomorrowtime column. Just wondering if anybody can spot what I'm doing wrong? Any help would be greatly appreciated! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/171664-adding-24-hours-to-current-time-and-saving-it-to-mysql-database/ Share on other sites More sharing options...
mikesta707 Posted August 24, 2009 Share Posted August 24, 2009 try echoing your timestamp1 variable. Also, what datatype is your SQL column? Quote Link to comment https://forums.phpfreaks.com/topic/171664-adding-24-hours-to-current-time-and-saving-it-to-mysql-database/#findComment-905194 Share on other sites More sharing options...
wildteen88 Posted August 24, 2009 Share Posted August 24, 2009 What is the data type set to for your tomorrowtime column? If its DATETIME then MySQL is expecting the following date format MM-DD-YY HH:MM:SS not a unix timestamp. For using dates in PHP have a read this tutorial Quote Link to comment https://forums.phpfreaks.com/topic/171664-adding-24-hours-to-current-time-and-saving-it-to-mysql-database/#findComment-905195 Share on other sites More sharing options...
debuitls Posted August 24, 2009 Author Share Posted August 24, 2009 Thanks for getting back to me so quickly! ok, it echo's out fine. So as you guys suggested I think its a problem with the format of the column in the database. I set it to timestamp originally and I obviously wasnt saving it in that format using time (). So i've changed the following to <? $timestamp = timestamp() ; $timestamp1 = $timestamp + 24 * 60 * 60; (database connection)... $sql="INSERT INTO proposal (tomorrowtime) VALUES ('$timestamp1')"; ?> But now im just getting a white screen when I load the page. I saw the timestamp() on a tutorial but maybe im not using it correctly? Any ideas? Thanks for your time Quote Link to comment https://forums.phpfreaks.com/topic/171664-adding-24-hours-to-current-time-and-saving-it-to-mysql-database/#findComment-905206 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.