Welcome Guest, Not a member yet? Register   Sign In
date/time timezones -suggestion
#1

[eluser]UnknownPlayer[/eluser]
Hi,
i have events website in CI, registred user can add new events, now i have question and suggestion.

In config i have set:
Code:
$config['time_reference'] = 'gmt';
date_default_timezone_set('UTC'); // don't know if this can help at all
When user go on page that show event, he gets time and date in his timezone:
Code:
$date = gmt_to_local($event->date, $this->session->userdata('timezone'), FALSE);
That will show time in his timezone, but now i have problem, when user want to add a new event.

If his timezone is "UP3" and he add a event, how should i save timestamp in db, now.
Example..
If user set "12/25/2012 13:00", how can i convert that from his timezone to gmt ? I think that local_to_gmt doesn't do that becouse there is no timezone attribute in that function.

I am trying to save all dates in gmt, so that will be default in db, and for each user to read at his timezone, is this bad way of solving this problem ?
And what is your suggestion for this problem ?
#2

[eluser]Aken[/eluser]
There are a couple solutions. You'll need to figure out which is best for you.

1) Save all dates in GMT in your MySQL DB as DATETIME columns. MySQL DATETIME uses the server's local timezone by default, so if you use functions like NOW(), it will pull the local time, so keep that in mind. This solution is a little more difficult to keep dates consistent, but allows you to use standard dates which can be easier to query / look at if you need to.

2) Save all dates as unix timestamps. They're the same for every timezone, so manipulating them is easier. But querying the DB can be more intensive and difficult, depending on what logic you need.

There may be other options, too, but these are the two most common for me.
#3

[eluser]UnknownPlayer[/eluser]
I use the second solution, save as now() codeigniter function, and in config is set "gmt", thanks for that.
But can you help me with converting timestamp from local users timezone to gmt ?
#4

[eluser]UnknownPlayer[/eluser]
Any solution ? Sad
Example, if user is in UP2(+2:00) and he set 12-25-2012 22:30:00 it will be converted to timestamp and saved in db, but it is incorrect, it should subtract 2:00 and save that timestamp to db as timestamp of 12-25-2012 20:30:00 (this is converted to gmt)




Theme © iAndrew 2016 - Forum software by © MyBB