CodeIgniter Forums

Full Version: How to Set Default date-time GMT -5 UM5?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I like know How to Set Default date-time GMT -5 UM5?

I have a problem because when i tried to save a date like date("y-m-d H:iConfused") this return the server date-time and not the user date-time, and becuase all users are in GMT -5, i need to make the Default date-time GMT -5 UM5, please help me!! Smile

El Forum

Most obvious solution, set the entire server in GMT-5. But probably not what you want.

Working with timezones is tricky business, even when you keep it simple and use CI's date helper functions. In general, whenever you need conversions, store all your timestamps in GMT. When a user posts a date, convert it to GMT before storing the date in the database (requires you to know the users timezone), when you need to display a date, you have to convert it back (again, you need to know the users timezone.

For the server, you can get the current time using now() instead of time(). Use that, and the date helper function gmt_to_local(), to convert a GMT timestamp to a different timezone.

Note that this can lead to incorrect results, as CI's functions can't handle daylight savings, can't handle differences in daylight saving periods around the globe (even within timezones), and can't deal with timestamps is the past or future (same reason).

If you want proper conversions, use PHP's DateTime() class (PHP 5.2+).