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

Helper function to create cross-database SQL dates.

Parameters

$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 338
Utility functions for assembling Views queries.

Code

function views_date_sql_field($field, $field_type = 'int', $set_offset = NULL) {
  $offset = $set_offset !== NULL ? $set_offset : views_get_timezone();
  if (isset($offset) && !is_numeric($offset)) {
    $dtz = new DateTimeZone($offset);
    $dt = new DateTime("now", $dtz);
    $offset_seconds = $dtz->getOffset($dt);
  }

  switch ($field_type) {
    case 'int':
      $field = "DATE_ADD('19700101', INTERVAL $field SECOND)";
      break;
    case 'datetime':
      break;
  }
  if (!empty($offset)) {
    $field = "($field + INTERVAL $offset_seconds SECOND)";
  }
  return $field;
}