Welcome Guest, Not a member yet? Register   Sign In
Multitimezone website
#1

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'); 
as in Turkey time same every where within Turkey.
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...
Reply
#2

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 )
Reply
#3

(This post was last modified: 02-26-2018, 11:25 PM by neuron.)

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?
Reply
#4

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 )
Reply
#5

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));
echo $date->format('...');
Reply
#6

(This post was last modified: 02-28-2018, 12:30 AM by neuron.)

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/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB