You are here

function date_sql_handler::sql_offset in Date 6

Same name and namespace in other branches
  1. 5.2 date_api_sql.inc \date_sql_handler::sql_offset()
  2. 6.2 date_api_sql.inc \date_sql_handler::sql_offset()
  3. 7.3 date_api/date_api_sql.inc \date_sql_handler::sql_offset()
  4. 7 date_api/date_api_sql.inc \date_sql_handler::sql_offset()
  5. 7.2 date_api/date_api_sql.inc \date_sql_handler::sql_offset()

Adjust a field value by an offset in seconds.

1 call to date_sql_handler::sql_offset()
date_sql_handler::sql_tz in ./date_api_sql.inc
Select a date value from the database, adjusting the value for the timezone.

File

./date_api_sql.inc, line 185

Class

date_sql_handler
A class to manipulate date SQL.

Code

function sql_offset($field, $offset = NULL) {
  if (!empty($offset)) {
    switch ($this->db_type) {
      case 'mysql':
      case 'mysqli':
        return "ADDTIME({$field}, SEC_TO_TIME({$offset}))";
      case 'pgsql':
        return "({$field} + 'INTERVAL {$offset} SECONDS')";
    }
  }
  return $field;
}