You are here

public function SqlsrvDateSql::getDateFormat 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::getDateFormat()
  2. 3.0.x src/Plugin/views/query/SqlsrvDateSql.php \Drupal\sqlsrv\Plugin\views\query\SqlsrvDateSql::getDateFormat()
  3. 3.1.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);

  // MS SQL does not have a ISO week substitution string, so it needs special
  // handling.
  // @see http://wikipedia.org/wiki/ISO_week_date#Calculation
  // @see http://stackoverflow.com/a/15511864/1499564
  if ($format === 'W') {
    return "DATEPART(iso_week, {$field})";
  }
  return "FORMAT({$field}, '{$format}')";
}