PDA

View Full Version : Timezone problem


nerhael
07-17-2003, 10:33 PM
There a nice and easy way when doing an insert, and wanting to get the sysdate(), to make sure that sysdate uses my particular time zones now() vs wherever the heck the server itself is?

Pete.

raf
07-17-2003, 10:50 PM
Yes. Using javascript. You can get the clients date-time with javascript and post it to the server, that inserts it as a value in a datetime field in your table.

But it's quite useless. It wount be 'your' time that is recorded, but the clients time, and that can be different for a whole lott of clients.

nerhael
07-17-2003, 10:54 PM
Well, it's not the clients time I'm after...what I mean is, I want all my times in the DB to be GMT -5 for instance...can I do that?

raf
07-17-2003, 11:10 PM
Hmm.

I'm at GMT + 1. So if i insert like
insert into table (datatime) values(Now())
i get GMT + 1 in that field, cause my systemdate is GMT +1. If i'd move my db to a server which systemdate is GMT +2, but i wan't the value still in GMT+1, then id probably use
insert into table (datatime) values(DATE_ADD(Now(), INTERVAL -1 HOUR)

So all you need to do is compute the differnce between the systemtime of the server, and the time you want it to be, and translate that into an interval.

More info
http://www.mysql.com/doc/en/Date_and_time_functions.html

nerhael
07-18-2003, 03:11 PM
I was hoping for something that would require me to not know where the server is, so that if it moved, no skin off my back.

However, this will work, as I don't expect it to move.

Many thanks again. :)