Jump to content

inserting time using NOW() + time


frustrated

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.