You are here

public function date_sql_handler::sql_offset in Date 7.2

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 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 for the timezone.

File

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

Class

date_sql_handler
A class to manipulate date SQL.

Code

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