Multitimezone website |
Hi,
This is first time I get project where I should consider multiple timezones. Although time precision is not critical in this project I want to build in a right way. So far in my projects I handle time in following way: 1. in index.php I set PHP Code: date_default_timezone_set('Europe/Istanbul'); 2. In in database I set time column as DATATIME type 3. and I set the value of the time columns with value from PHP Code: $date['created_at'] = date((time(), 'Y-m-d hh:mm:ss'); And now I working on a project (Which give consultation service, also consultants will give appoitment for users for online conversation) that will have users from different countries. How should I handle time here? Thanks in advance...
See this may help you out:
CodeIgniter Users Guide - Date Helper What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Hi,
It is not what I am asking. I am asking: 1. Should I continue use DATETIME as type of time field in db. or I should use TIMESTAMP. or even integer and use unix time. 2. I am want to know how you guys handled time in this situation?
DATETIME type - has a range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
TIMESTAMP type - has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC. Read the below article, they use a DATETIME field. Multilanguage Database Design in MySQL What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Because of potential differences in timezone settings between server and database, I find it's best to set the timezone in the application to UTC for these types of websites. That's what most databases default to, I believe. Then store a timezone / offset for each user, and a system wide default timezone (in case the user's haven't specified a timezone). Then you can use PHP's DateTime and DateTimeZone to display the correct time, adjusted for the user's timezone. Something like:
Code: $date = new DateTime($originalDate, new DateTimeZone($userTimezone));
Thanks Kilishan, that is the answer I needed.
I found nice article to handle timezone here https://www.sitepoint.com/working-with-dates-and-times/ |
Welcome Guest, Not a member yet? Register Sign In |