1 date_sql_handler.inc date_sql_handler::sql_format($format, $field)

Helper function to create cross-database SQL date formatting.

Parameters

string $format: A format string for the result, like 'Y-m-d H:i:s' .

string $field: The real table and field name, like 'tablename.fieldname' .

Return value

string: An appropriate SQL string for the db type and field type.

File

core/modules/date/views/date_sql_handler.inc, line 238
SQL helper for Date API.

Class

date_sql_handler
A class to manipulate date SQL.

Code

function sql_format($format, $field) {
  $replace = array(
    'Y' => '%Y',
    'y' => '%y',
    'M' => '%b',
    'm' => '%m',
    'n' => '%c',
    'F' => '%M',
    'D' => '%a',
    'd' => '%d',
    'l' => '%W',
    'j' => '%e',
    'W' => '%v',
    'H' => '%H',
    'h' => '%h',
    'i' => '%i',
    's' => '%s',
    'A' => '%p',
    '\WW' => 'W%U',
  );
  $format = strtr($format, $replace);
  return "DATE_FORMAT($field, '$format')";
}