You are here

public function SqlsrvDateSql::getDateFormat in Drupal driver for SQL Server and SQL Azure 3.1.x

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

Creates a native database date formatting.

Parameters

string $field: An appropriate query expression pointing to the date field.

string $format: A format string for the result. For example: 'Y-m-d H:i:s'.

Return value

string A string representing the field formatted as a date as specified by $format.

Overrides DateSqlInterface::getDateFormat

File

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

Class

SqlsrvDateSql
MSSQL-specific date handling.

Namespace

Drupal\sqlsrv\Plugin\views\query

Code

public function getDateFormat($field, $format) {
  $format = strtr($format, static::$replace);
  if ($format === 'W') {
    return "DATEPART(iso_week, {$field})";
  }
  return "FORMAT({$field}, '{$format}')";
}