A PHP timezone setting does not automatically change the MariaDB session or reinterpret values already stored in a DATETIME column. Use one storage convention—normally UTC—then convert to a named local timezone at the presentation boundary.
Last updated: November 3, 2026.
<?php
// In .env, set: app.appTimezone = UTC
use CodeIgniter\I18n\Time;
$db = db_connect();
$db->query("SET time_zone = '+00:00'");
$stored = Time::now('UTC')->toDateTimeString();
$local = Time::parse($stored, 'UTC')
->setTimezone('America/Guatemala');The application creates and stores an unambiguous UTC value. The final conversion changes only the displayed representation; it does not change the instant in time.
Configure the framework instead of changing it late
CodeIgniter configuration properties can be replaced from .env with namespaced variables. The official configuration documentation recommends treating configuration objects as immutable after construction, so changing the default timezone in a controller constructor is the wrong layer.
Use an IANA name such as America/Guatemala for user-facing conversions because named zones carry historical offset rules. Use UTC for storage, logs, queues, and API timestamps. A fixed offset is acceptable for the database session’s UTC setting, but it should not replace a named zone for locations that observe daylight-saving changes.
Know what the database column stores
CodeIgniter’s Time class accepts an explicit timezone and returns immutable converted instances. Pass the timezone instead of relying on a process-wide default that a worker, test, or container may configure differently.
MariaDB DATETIME stores the literal date and time you send; it does not remember a timezone. TIMESTAMP is converted according to the database session timezone. Do not mix local DATETIME values with UTC values in the same column. Record the storage convention in the schema documentation and test one known instant end to end.
If existing rows are six hours ahead, first determine which convention produced them. Correct only rows whose original timezone is known; blindly subtracting six hours can damage records created under another offset. Continue with MySQL time zone tables, CodeIgniter URL configuration, and date comparisons in MySQL.