You are here

function DateSqlHandler::sql_offset in Date 8

Adjust a field value by an offset in seconds.

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

File

date_api/lib/Drupal/date_api/DateSqlHandler.php, line 189

Class

DateSqlHandler
A class to manipulate date SQL.

Namespace

Drupal\date_api

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')";
      case 'sqlite':
        return "datetime({$field}, '{$offset} seconds')";
      case 'sqlsrv':
        return "DATEADD(second, {$offset}, {$field})";
    }
  }
  return $field;
}