MySQL NOW function Minus Four hours (bad server time)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

MySQL NOW function Minus Four hours (bad server time)

Post by JAB Creations »

My current host (the genius that he is) has the server set four hours ahead of us. I currently use the NOW() function to create a time stamp though it there a reasonably way to adjust the hours so I'm looking at the time from my own time zone? Suggestions for using something other then the now function are welcomed too.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: MySQL NOW function Minus Four hours (bad server time)

Post by it2051229 »

i'm using oxyhost for my website.. we have the same problem actually.. but the solution that they have provided is in the .HTaccess... if you know how to code on .htaccess, you can set your own time zone there... IF your host allows you
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: MySQL NOW function Minus Four hours (bad server time)

Post by JAB Creations »

I added this however I don't think it had much if any effect?

Code: Select all

SetEnv TZ America/New_York
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: MySQL NOW function Minus Four hours (bad server time)

Post by it2051229 »

well .htaccess can be modified but only works if the host allows it so.. to make things sure you can write email to the host like you know i think they have forums where you can post questions and also ask them how to place the .htaccess code for timezone
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: MySQL NOW function Minus Four hours (bad server time)

Post by onion2k »

.htaccess won't change the value MySQL gets with it's NOW() function will it?

Use "SET time_zone = '+4:00';". You'll need to do it every time you connect to mysql, so your database connection file will likely look something like:

Code: Select all

mysql_connect('localhost', 'username', 'password');
mysql_select_db('mydatabase');
 
mysql_query("SET time_zone = '+4:00';");
If that doesn't work, try DATE_ADD(NOW(), INTERVAL 4 HOUR) in place of NOW().
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: MySQL NOW function Minus Four hours (bad server time)

Post by JAB Creations »

That worked! Thanks a ton Onion! :mrgreen:

Code: Select all

mysql_query("SET time_zone = '-4:00';");
Post Reply