frustrated Posted January 15, 2006 Share Posted January 15, 2006 Ok...I'm trying to insert the time into a database using the mysql NOW() function, but I wanted to offset the time to my actual time zone. For instance, the server the site is hosted on is in California, but I live in New Hampshire. I want the time in the database to reflect New Hampshire time as opposed to California time...it's like a 3 hour difference. My inclination was to do something like this $time_offset = /* Would equal the difference in time */ $sql = "INSERT INTO the_table (the_date) VALUES ((NOW() - $time_offset))"; Am I on the right track or is this not even possible with the NOW() function...or not possible at all? Thanks for any help. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 15, 2006 Share Posted January 15, 2006 If this is something you want to do on a more global basis, you should probably read [a href=\"http://dev.mysql.com/doc/refman/4.1/en/time-zone-support.html\" target=\"_blank\"]this refman page[/a]. For a one-time thing, though, you should probably be using something like "DATE_SUB(NOW(), INTERVAL $time_offset HOUR)". Hope that helps. Quote Link to comment Share on other sites More sharing options...
frustrated Posted January 15, 2006 Author Share Posted January 15, 2006 Nice, that helps a lot. I read the page you linked to. It would be nice to use that method but I don't think I have enough control over the database to do something like. I have no money and can only afford shared hosting Quote Link to comment Share on other sites More sharing options...
fenway Posted January 15, 2006 Share Posted January 15, 2006 What does money have to do with it? Even if you don't have permission to do it for the whole DB, you can always reset the time zone for all of your client sessions, which has the exact same effect! Does that make sense? Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted January 15, 2006 Share Posted January 15, 2006 exactly [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]# Per-connection time zones. Each client that connects has its own time zone setting, given by the session time_zone variable. Initially this is the same as the global time_zone variable, but can be reset with this statement: mysql> SET time_zone = timezone; Just put this query in the connection.php of your script. Quote Link to comment Share on other sites More sharing options...
frustrated Posted January 15, 2006 Author Share Posted January 15, 2006 Cool, I'll do that then. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.