Php timezones, mysql dates.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
burnthewitches
Forum Newbie
Posts: 4
Joined: Sat Feb 04, 2006 7:14 pm

Php timezones, mysql dates.

Post by burnthewitches »

Hi,

I use putenv('TZ= to change the time zone in a script...

what I want is to find the time difference between mysql and the new time from php and use it on mysql...
I don't want to use 'SET time_zone=' in mysql because only works after some version...

iI supose I should do something like:
$mysql_time = mysql datetime
$php_time = date("Y-m-d H:i:s")

now my problem is how to get the time difference between these two so I can use it in a query like:
SELECT now()
and get the same datetime as in php?
(probably use addtime but still I'm very confused! :( )

ps. really sorry if this makes no sense
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it can be suggested that simply storing the unix timestamp from php can work easiest. time() will return the local time, gmmktime() will return the current time in GMT (use this) .. since that is a known reference, you can then use simple math to offset it to any timezone.
User avatar
burnthewitches
Forum Newbie
Posts: 4
Joined: Sat Feb 04, 2006 7:14 pm

Post by burnthewitches »

edit: please forget this I'll do this as feyd sugested! ^_^
thnx again feyd! :)
Post Reply