adding 24 hours to current time and saving it to mysql database
Sorry i'm very new to php and I think this might be a very basic question.
I'm trying to add 24 hours to the current time and save it in a mysql database.
At the moment im just gettin a series of 0s when I save to the database
$time1 = time () + 24 * 60 * 60;
The column im trying to save it in, is of datatype "timestamp".
So I think i need to convert the value stored in $time1 to a timestamp format?
Can anyone suggest if I'm going about this in the right way? and if I am how do I go about making the conversion.
If anyone has any suggestions it would be a massive help.
Or you could let MySQL do the work:
$timePlus24Hr = date('Y-m-d H:i:s', time() + 24 * 60 * 60);
INSERT INTO `table` (`col_name`) VALUES ( DATE_ADD( NOW(), INTERVAL 24 HOUR ) )
Thanks for getting back to me NogDog.
This works perfectly.
This is so much easier:
It's a very useful function, but you still need to convert it to a "yyyy-mm-dd hh:mm:ss" string to be used in the SQL.
Originally Posted by Teufel
$sqlTime = date('Y-m-d H:i:s', strtotime('+24 hours'));
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)