CodeIgniter Forums

Full Version: Each user can set timezone
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Exemple

Code:
date_default_timezone_set($user->timezone)

How do I do it in Codeigniter? I tried to put in the MY_Controller of Core, which is the main controller of my system. Only it does not work. It only works if I put in index.php or constants.php. But it can't be read from Model to get user data for what I want to do.
(10-13-2019, 10:10 AM)esjdev Wrote: [ -> ]Exemple

Code:
date_default_timezone_set($user->timezone)

How do I do it in Codeigniter? I tried to put in the MY_Controller of Core, which is the main controller of my system. Only it does not work. It only works if I put in index.php or constants.php. But it can't be read from Model to get user data for what I want to do.
 

@esjdev,
Maybe this is what you are looking for... https://www.php.net/manual/en/function.d...ne-set.php
(10-13-2019, 01:40 PM)php_rocs Wrote: [ -> ]
(10-13-2019, 10:10 AM)esjdev Wrote: [ -> ]Exemple

Code:
date_default_timezone_set($user->timezone)

How do I do it in Codeigniter? I tried to put in the MY_Controller of Core, which is the main controller of my system. Only it does not work. It only works if I put in index.php or constants.php. But it can't be read from Model to get user data for what I want to do.
 

@esjdev,
Maybe this is what you are looking for... https://www.php.net/manual/en/function.d...ne-set.php

I know how the function works, the question and what in codeigniter doesn't work. This is my question Big Grin
(10-13-2019, 10:10 AM)esjdev Wrote: [ -> ]But it can't be read from Model to get user data for what I want to do.

What can't be read? The function you show sets the timezone.
(10-13-2019, 04:07 PM)dave friend Wrote: [ -> ]
(10-13-2019, 10:10 AM)esjdev Wrote: [ -> ]But it can't be read from Model to get user data for what I want to do.

What can't be read? The function you show sets the timezone.

It only works if I put "date_default_timezone_set ('UTC')" directly in index.php or constants.php, but I can't get the user's timezone in a database, as I want.
Not sure but this may be what your looking for, you need to be more specific about
your problem.

How To Synchronize Your PHP and MySQL Timezones 
@esjdev,

What variable type is $user->timezone? String? Also, what values do you allow it to be?
(10-14-2019, 07:18 AM)php_rocs Wrote: [ -> ]@esjdev,

What variable type is $user->timezone? String?  Also, what values do you allow it to be?

This variable gets the specific user's Timezone from the database.
The recommended way are storing all time in UTC or GMT (whatever you prefer) and then use PHP DateTime to diff the time to the users timezone. If I remember correctly using that function mentioned can result in odd behavior as it affects all users in that PHP process.

Here is an guide to do it.
https://blog.serverdensity.com/handling-...-datetime/
(10-14-2019, 10:39 AM)jreklund Wrote: [ -> ]The recommended way are storing all time in UTC or GMT (whatever you prefer) and then use PHP DateTime to diff the time to the users timezone. If I remember correctly using that function mentioned can result in odd behavior as it affects all users in that PHP process.

Here is an guide to do it.
https://blog.serverdensity.com/handling-...-datetime/

Thanks, I will try thisWink
Pages: 1 2