Bebopgeo Posted January 2, 2010 Share Posted January 2, 2010 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 More sharing options...
Ingolme Posted January 2, 2010 Share Posted January 2, 2010 Usually the server time is different than your computer time. Link to comment Share on other sites More sharing options...
tal Posted January 2, 2010 Share Posted January 2, 2010 if you have access to php.ini look for this line to set your server time zonedate.timezoneor set it on the fly Link to comment Share on other sites More sharing options...
Redroest Posted January 3, 2010 Share Posted January 3, 2010 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 More sharing options...
Guest FirefoxRocks Posted January 3, 2010 Share Posted January 3, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.