I am trying to set the timezone for codeigniter v4 and if I set using php code, it is setting in IST, whereas the updated_at column is still at UTC timezone.
From the below records
the created_at and last_active_on, both columns, are in IST timezone.
The updated_at is in UTC timezone. How do I set the timezone for the mysql specific only for this database.
I tried from link with below code
$this->db->query("SET time_zone='+05:30'");
in vendor\codeigniter4\framework\system\Model.php
it did not work. Also this is changing the library file, which is not recommended.
Below is my code (incase if you need a reference)
$activityObj = new Activity;
$activity = $activityObj->where('user_id', $user['id'])->first();
$data = ['last_active_on' => date('Y-m-d H:i:s')];
if (empty($activity)) {
$data['user_id'] = $user['id'];
$data['created_at'] = date('Y-m-d H:i:s');
$activityObj->save($data);
} else {
$activityObj->where('user_id', $user['id'])
->set($data)
->update();
}

$useTimestampsin your model? 2. You can use the initialize() function which allows you to run a query for the model without having to modify the base model. 3. Bear in mind a utc timestamp will be just that. You might want to set php.net/manual/en/function.date-default-timezone-set.php and see if that fixes it.