1 utility.inc views_date_sql_format($format, $field, $field_type = 'int', $set_offset = NULL)

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'.

$field_type: The type of date field, 'int' or 'datetime'.

$set_offset: The name of a field that holds the timezone offset or a fixed timezone offset value. If not provided, the normal Backdrop timezone handling will be used, i.e. $set_offset = 0 will make no timezone adjustment.

Return value

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

File

core/modules/views/includes/utility.inc, line 378
Utility functions for assembling Views queries.

Code

function views_date_sql_format($format, $field, $field_type = 'int', $set_offset = NULL) {
  $field = views_date_sql_field($field, $field_type, $set_offset);
  $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',
  );
  $format = strtr($format, $replace);
  return "DATE_FORMAT($field, '$format')";
}