0 follower

Final Class Yiisoft\Db\Mysql\Column\DateTimeColumn

InheritanceYiisoft\Db\Mysql\Column\DateTimeColumn » Yiisoft\Db\Schema\Column\DateTimeColumn

Represents the metadata for a datetime column.

[!WARNING] MySQL DBMS converts TIMESTAMP column type values from database session time zone to UTC for storage, and back from UTC to the session time zone when retrieve the values.

TIMESTAMP database type does not store time zone offset and require to convert datetime values to the database session time zone before insert and back to the PHP time zone after retrieve the values. This will be done in the {@see \Yiisoft\Db\Mysql\Column\dbTypecast()} and {@see \Yiisoft\Db\Mysql\Column\phpTypecast()} methods and guarantees that the values are stored in the database in the correct time zone.

To avoid possible time zone issues with the datetime values conversion, it is recommended to set the PHP and database time zones to UTC.

Method Details

Hide inherited methods

getFormat() protected method

protected string getFormat ( )

                protected function getFormat(): string
{
    return $this->format ??= match ($this->getType()) {
        ColumnType::DATETIMETZ => 'Y-m-d H:i:s' . $this->getMillisecondsFormat(),
        ColumnType::TIMETZ => 'H:i:s' . $this->getMillisecondsFormat(),
        default => parent::getFormat(),
    };
}

            
shouldConvertTimezone() protected method

protected boolean shouldConvertTimezone ( )

                protected function shouldConvertTimezone(): bool
{
    return $this->shouldConvertTimezone ??= !empty($this->dbTimezone) && $this->getType() !== ColumnType::DATE;
}