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
https://forums.phpfreaks.com/topic/3202-inserting-time-using-now-time/
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.

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.

Archived

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

×
×
  • 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.