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
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);
}