Reputation: 5442
I use php's date_default_timezone_set()
and set it according to user's timezone
field in the the user table. So with ease I can show date/time to users and get date/time from them.
But for storing date related values in database, I have to use the standard GMT timezone.
The question: What is the best or maybe the standard way for switching to/from user_timezone and GMT?
Do you suggest me to follow these steps when I want to insert or update a field in database?
date_default_timezone_set('GMT');
$inserttimestap = time();
or $inserttimestamp
= mktime();
date_default_timezone_set($this->session->userdata('timezone'));
Upvotes: 0
Views: 183
Reputation: 5442
There is absolutely no need to use date_default_timezone_set('GMT')
because for converting to GMT, there is a special set of functions that the function names begin with 'gm':
gmmktime()
gets a timestamp in GMT timezone.gmdate()
that gives a GMT date format.There is also gmstrftime()
PHP manual
Furthermore it's notable that the time()
returns current timestamp only in GMT
Upvotes: 1