function date_sql_handler::sql_format in Date 6
Same name and namespace in other branches
- 5.2 date_api_sql.inc \date_sql_handler::sql_format()
- 6.2 date_api_sql.inc \date_sql_handler::sql_format()
- 7.3 date_api/date_api_sql.inc \date_sql_handler::sql_format()
- 7 date_api/date_api_sql.inc \date_sql_handler::sql_format()
- 7.2 date_api/date_api_sql.inc \date_sql_handler::sql_format()
Helper function to create cross-database SQL date formatting.
Parameters
$format: A format string for the result, like 'Y-m-d H:i:s'.
$field: The real table and field name, like 'tablename.fieldname'.
Return value
An appropriate SQL string for the db type and field type.
1 call to date_sql_handler::sql_format()
- date_sql_handler::sql_where_format in ./
date_api_sql.inc - Create a where clause to compare a formated field to a formated value.
File
- ./
date_api_sql.inc, line 259
Class
- date_sql_handler
- A class to manipulate date SQL.
Code
function sql_format($format, $field) {
switch ($this->db_type) {
case 'mysql':
case 'mysqli':
$replace = array(
'Y' => '%Y',
'y' => '%y',
'm' => '%m',
'n' => '%c',
'd' => '%%d',
'j' => '%e',
'H' => '%H',
'i' => '%i',
's' => '%s',
);
$format = strtr($format, $replace);
return "DATE_FORMAT({$field}, '{$format}')";
case 'pgsql':
$replace = array(
'Y' => 'YY',
'y' => 'Y',
'm' => 'MM',
'n' => 'M',
'd' => 'DD',
'j' => 'D',
'H' => 'HH24',
'i' => 'MI',
's' => 'SS',
);
$format = strtr($format, $replace);
return "TO_CHAR({$field}, '{$format}')";
}
}