Jump to content

adding 24 hours to current time and saving it to mysql database


debuitls

Recommended Posts

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

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

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

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.