Jump to content

Input Current Date And Time In To The Database


Bebopgeo

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

Using php to get the right timezone:

<?phpecho "Original Time: ". date("h:i:s")."\n";//Set timezoneputenv("TZ=US/Eastern");echo "New Time: ". date("h:i:s")."\n";?>

You can also use javascript to take the clientside time when there is no real security related issue.

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

Archived

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

×
×
  • Create New...