Multitimezone website - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Multitimezone website (/showthread.php?tid=70133) |
Multitimezone website - neuron - 02-25-2018 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... RE: Multitimezone website - InsiteFX - 02-26-2018 See this may help you out: CodeIgniter Users Guide - Date Helper RE: Multitimezone website - neuron - 02-26-2018 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? RE: Multitimezone website - InsiteFX - 02-27-2018 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 RE: Multitimezone website - kilishan - 02-27-2018 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)); RE: Multitimezone website - neuron - 02-27-2018 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/ |