Jump to content

Input Current Date And Time In To The Database


Bebopgeo
 Share

Recommended Posts

I have a hidden field in my insert form that will insert the date into my mysql database. I'm using a "varchar" field in the database if that is the right type to use, and I have this pice of code in the value of the hidden field

 <?php echo date("m/d/Y H:i:s") ?>

I'm trying to insert the current date and time of my computer into the database I get the right date but the time is off by five hours or so. So is the code right or do I need to change the code or use a DATE/TIME field in the database.

Link to comment
Share on other sites

Guest FirefoxRocks

Actually in PHP5 they recommend using date_default_timezone_set:

<?phpecho "Original Time: ". date("h:i:s")."\n";date_default_timezone_set("America/Rainy_River);echo "New Time: ". date("h:i:s")."\n";?>

In fact, lacking that statement when using any date or time functions will throw an E_NOTICE error, they are visible when all errors are displayed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...