Forum Moderators: coopster

Message Too Old, No Replies

MYSQL DATETIME to Local Time

         

username

8:59 pm on Mar 6, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi,

I need to convert a MYSQL DATETIME value i.e 2008-12-31 14:59:31, to the time that would be dependent on where you are in the world. My server adheres to the timezone it is in, and the datetime displays only as entered currently. I would like it to display taking into account the timezone differences. So if there is a 8 hour time difference at that time, it would be 06:59:31 etc.

Thanks in advance.

coopster

7:34 pm on Mar 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You can attempt to determine where the user is at by using geographical location by ip address, but it is not without it's faults. The best way is to ask the user their timezone and adjust accordingly in your code. There are also some JavaScript tricks you can use, which is basically pulling the time from their machine and pushing it back to you.

username

8:52 pm on Mar 7, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



So there are no PHP functions to do this? I was looking through php.net, and found get_timezone and a few others which seemed to just set a timezone. Maybe if I could get a timezone, I could adjust the datetime + or - hours dependent on where they are? This would not be very stable though. I have seen this on other sites, surely it is possible somehow?

coopster

9:12 pm on Mar 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



PHP is a server-side technology. So let's say your server is in the eastern United States. Your server may have it's time zone set to EST, which is UTC-5. How are you going to know where I am?

That is why I mentioned geoip. There are some databases that offer IP-to-geographical-location references. Somewhat decent, but still not entirely accurate. Best case? Ask me! I tell you where I am and then you adjust the date delivery from your server to show me my time in reference to yours.