You are here

public function SqlsrvDateSql::getDateField in Drupal driver for SQL Server and SQL Azure 8

Same name and namespace in other branches
  1. 4.2.x src/Plugin/views/query/SqlsrvDateSql.php \Drupal\sqlsrv\Plugin\views\query\SqlsrvDateSql::getDateField()
  2. 3.0.x src/Plugin/views/query/SqlsrvDateSql.php \Drupal\sqlsrv\Plugin\views\query\SqlsrvDateSql::getDateField()
  3. 3.1.x src/Plugin/views/query/SqlsrvDateSql.php \Drupal\sqlsrv\Plugin\views\query\SqlsrvDateSql::getDateField()
  4. 4.0.x src/Plugin/views/query/SqlsrvDateSql.php \Drupal\sqlsrv\Plugin\views\query\SqlsrvDateSql::getDateField()
  5. 4.1.x src/Plugin/views/query/SqlsrvDateSql.php \Drupal\sqlsrv\Plugin\views\query\SqlsrvDateSql::getDateField()

Returns a native database expression for a given field.

Parameters

string $field: The query field that will be used in the expression.

bool $string_date: For certain databases, date format functions vary depending on string or numeric storage.

Return value

string An expression representing a date field with timezone.

Overrides DateSqlInterface::getDateField

File

src/Plugin/views/query/SqlsrvDateSql.php, line 61

Class

SqlsrvDateSql
MSSQL-specific date handling.

Namespace

Drupal\sqlsrv\Plugin\views\query

Code

public function getDateField($field, $string_date) {
  if ($string_date) {
    return "CONVERT(datetime2, {$field}, 127)";
  }

  // Base date field storage is timestamp, so the date to be returned here is
  // epoch + stored value (seconds from epoch).
  return "DATEADD(second, {$field}, '19700101')";
}