function views_date_sql_field

Same name in other branches
  1. 7.x-3.x includes/handlers.inc \views_date_sql_field()

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

2 calls to views_date_sql_field()
views_date_sql_extract in includes/handlers.inc
Helper function to create cross-database SQL date extraction.
views_date_sql_format in includes/handlers.inc
Helper function to create cross-database SQL date formatting.

File

includes/handlers.inc, line 1181

Code

function views_date_sql_field($field, $field_type = 'int', $set_offset = NULL) {
    $db_type = $GLOBALS['db_type'];
    $offset = $set_offset !== NULL ? $set_offset : views_get_timezone();
    switch ($db_type) {
        case 'mysql':
        case 'mysqli':
            switch ($field_type) {
                case 'int':
                    $field = "FROM_UNIXTIME({$field})";
                    break;
                case 'datetime':
                    break;
            }
            if (!empty($offset)) {
                $field = "({$field} + INTERVAL {$offset} SECOND)";
            }
            return $field;
        case 'pgsql':
            switch ($field_type) {
                case 'int':
                    $field = "{$field}::ABSTIME";
                    break;
                case 'datetime':
                    break;
            }
            if (!empty($offset)) {
                $field = "({$field} + INTERVAL '{$offset} SECONDS')";
            }
            return $field;
    }
}