views:

131

answers:

4

Hai

I have the system with employees having different timezones in their profile. I would like to show the date according to their timezones specified. The GMT time zone values are placed in the database. could you guys help me

A: 

Check out PHP's timezone-setting functions, including date_timezone_set.

Amber
A: 

in addition to Dav's answer i propose to store all time data in "timestamp" mysql datatype because it automatically handles timezones

zerkms
+1  A: 

Let’s say your server is located in the usa and store dates in database with local us gmt -7 So you send the local offset -7 and the offset of the employee country, lets say some where in Europe +2.

So basically you just need to know what is -7 -2 and its 9 hours offset, so each date you have stored in the database must be added 9 hours to represent the time in Europe.

  • > this will count the offset: fnGetOffset($source_gmt_offset ,$fltGmtOffset){ $intGmtOffest = $source_gmt_offset - $fltGmtOffset; if ( $intGmtOffest <> 0){ return $intGmtOffest; } }

After you count the offset you just need to get the date from the db and add to it the offset. Like that - >

$intUnixTimeStamp += $intGmtOffest*60*60;

So this is the proper way to do it with php. And if you want to query the server based on user selected time you need to go back -9 .

alex
thanks alex, could you please give me some example dates workout
Thinker
you are very much welcome, i posted anther reply with mysql code example.
alex
A: 
alex