You are here

function date_sql_handler::sql_offset in Date 7

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. 6 date_api_sql.inc \date_sql_handler::sql_offset()
  4. 7.3 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.

2 calls to date_sql_handler::sql_offset()
date_sql_handler::sql_field in date_api/date_api_sql.inc
Helper function to create cross-database SQL dates.
date_sql_handler::sql_tz in date_api/date_api_sql.inc
Select a date value from the database, adjusting the value for the timezone.

File

date_api/date_api_sql.inc, line 208
SQL helper for Date API.

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;
}