Back to Date class

Method toSql

public string
toSql
(mixed $local = false, \Joomla\Database\DatabaseDriver $db = null)
Gets the date as an SQL datetime string.
Parameters
  • bool $local True to return the date string in the local time zone, false to return it in GMT.
  • \Joomla\Database\DatabaseDriver $db The database driver or null to use Factory::getDbo()
Returns
  • string The date string in SQL datetime format.
Since
  • 2.5.0
-
  • http://dev.mysql.com/doc/refman/5.0/en/datetime.html
Class: Date
Project: Joomla

Method toSql - Source code

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