CodeIgniter Forums
timezone help - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: timezone help (/thread-49041.html)

Pages: 1 2

timezone help - El Forum - 02-06-2012

i found this code in config.php:
$config['time_reference'] = 'local';
and i wonna know, how this work, becouse when i write time() in db, how that would be saved, on which timezone ?
And when echo that to users in different timezones ?


timezone help - El Forum - 02-06-2012

That config item is utilized in Date helper functions and the Session library. If you're interested in displaying dates differently based on the visitor's time zone, you should save all dates in GMT. That would mean not using your database's built-in time functions (like NOW()), as those will use the database's local time.

timezone help - El Forum - 02-06-2012

So, you suggest to use $config['time_reference'] = 'gmt' or another way ?

When i set set GMT, and when insert in db, that will be ok, but when user is registred and he set GMT +1 as his default, now when he insert something in db(example: comment) it will be GMT +1, do i need to reset on every db insert ?

timezone help - El Forum - 02-06-2012

First off you need to set the correct time of where your server is!
I add this to the top of index.php for my servers time!
*  set the default timezone.

Now all time caculations will be correct for the servers time.

If the time is not correct sessions and cookies will not work correct!

Then use this if you are allowing users to set their timezones to gmt.
$config['time_reference'] = 'gmt';

CodeIgniter User Guide - Date Helper now()

Also look at ./system/helpers/date_helper.php

timezone help - El Forum - 02-06-2012

User will have to choose timezone on his profile.

Now what should be changed for each user.

- user1 | timezone (America/New_York)
- user2 | timezone (Europe/Belgrade)
- user3 | timezone (Asia/Baghdad)

this data will be saved in mysql ofc, now when user login, what should be loaded every page to make date to his timezone ?
But when he insert something, to make GMT like Aken said that is best for mysql insert.

timezone help - El Forum - 02-06-2012

You need to allow them to set their timezone using gmt time.
It has to be an offset to your gmt time. Do a search on gmt time...

timezone help - El Forum - 02-06-2012

I tried like this, but not showing correct time..
btw i tried this on my localhost, and i am in Serbia.
// time() will return new york time, i will use this to store every time and date in db  
$time = now();
$timezone = 'UP1'; // serbia timezone utc + 1
$daylight_saving = TRUE;  
$local_time = unix_to_human(gmt_to_local($time, $timezone, $daylight_saving));  
echo $local_time;

I just set on $config['time_reference'] = 'gmt'.

Now it shows me 1 hour more than it should be..

What is problem ?

I removed daylight saving from gmt_to_local and it works, should it be ok like that ?

Now i will store users time zone at some variable and use it like this.. i think that is the way..

timezone help - El Forum - 02-06-2012

You need to read this!


timezone help - El Forum - 02-07-2012

But this method is working nice ?

timezone help - El Forum - 02-07-2012

[eluser]Bhashkar Yadav[/eluser]
it can be done from .htaccess also by
php_value date.timezone 'YOUR TIME ZONE'

it would work nicely ....