Welcome Guest, Not a member yet? Register   Sign In
Changing the MySQL Timezone
#1

(This post was last modified: 09-27-2023, 05:00 AM by Roel.)

Hi,
Before in CodeIgniter 3 I used to change the MySQL timezone with a query inside MY_Controller.
Now in CodeIgniter 4 I'm doing the same in the BaseController:
PHP Code:
public function initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
{
        // Do Not Edit This Line
        parent::initController($request$response$logger);

        

        date_default_timezone_set
('Europe/Amsterdam');
        $utc_offset =  date('P');

        $db = \Config\Database::connect();
        $db->query('SET time_zone = "'$utc_offset .'"'); 


I double checked, and it's running the query okay.
However when I retrieve data from the database, the datetimes are still on mysql server timezone UTC.
Ofcourse I can converse every datetime I retrieve from the database in my PHP code, however I prefer not to do this, as it will require me to do this on many points.

Thank you,
Roel.

I solved the issue, it seems if I use time or datetime in the data column type it does notchange it by timezone, only when using the timestamp column type.
Reply
#2

I found this, not sure if it will help you.

Should MySQL have its timezone set to UTC?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB