0

Why is turning a date ->toSql losing the timezone value?

var_dump(Factory::getDate('now', $this->app->get('offset'))->toSql());

2023-09-14 17:10:04

var_dump(Factory::getDate('now', $this->app->get('offset')));

2023-09-14 19:10:04.627966

0

1 Answer 1

0

You need to set a flag, true or false, as to whether you want the local time or not in the toSql() function.

The comments for the toSql function explain what is required.

    /**
     * Gets the date as an SQL datetime string.
     *
     * @param   boolean         $local  True to return the date string in the local time zone, false to return it in GMT.
     ...
     */
    public function toSql($local = false, DatabaseDriver $db = null)
    {
        ...
        return $this->format($db->getDateFormat(), $local, false);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.