/**
 * 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.
 * @param   DatabaseDriver  $db     The database driver or null to use Factory::getDbo()
 *
 * @return  string     The date string in SQL datetime format.
 *
 * @link    http://dev.mysql.com/doc/refman/5.0/en/datetime.html
 * @since   2.5.0
 */
public function toSql($local = false, DatabaseDriver $db = null)
{
    if ($db === null) {
        $db = Factory::getDbo();
    }
    return $this->format($db->getDateFormat(), $local, false);
}