I am needing to convert date/timezone to an end user. I am trying to write a script that will allow professionals to setup a meeting time in a database in their timezone but automatically convert to other users in their stored timezone:
So I have a meeting time database:
Date -Time - Timezone
11-15-2012 - 9:00 P.M - America/Indiana/Tell_City
11-15-2012 - 10:00 A.M - America/Kentucky/Louisville
11-15-2012 - 7:00 A.M - America/Chicago
The end user has their timezone stored in the database
Username - TimeZone
Test - America/Indianapolis
How would I get the data from the first table of meeting for instance that is in the America/Chicago timezone to automatically show in the America/Indianapolis timezone of the end user?
I’d make sure that all program logic uses the same (server) time zone. Create a timezone table with timezone name and timezone offset (positive or negative integer) compared to your server timezone. If the user has specified a desired timezone in the user table, then apply the correction from the integer in your table.
users
user_id
user_name
time_zone_name
time_zones
time_zone_name
time_zone_offset int
//login form, define users time zone offset compared to your db
// $result = SQL result 'select time_zone_offset from time_zones t inner join users u on t.time_zone_name = u.time_zone_name where u.user_id = $userId' 0 if null or not defined
$_SESSION['userTimeZoneOffset'] = $result;
//any location where times are displayed
if ($_SESSION['userTimeZoneOffset'] != 0) {
$meetingTime = date($meetingTime, strtotime ($_SESSION['userTimeZoneOffset'] . " hour"));
}
Untested of course, but this is a general idea of how it can be done. I’m a little iffy on the strtotime() function syntax as I don’t think I’ve had to use it before.