Jump to content

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


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

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.