1.20.x database.inc | public DatabaseConnection_mysql::dateExtractSql($field, $extract_type) |
Extract part of a date from a date field.
Parameters
string $extract_type: The type of value to extract from the date, like 'MONTH'.
string $field: The real table and field name, like 'tablename.fieldname'.
Return value
string: An appropriate SQL string for the db type and field type.
Overrides DatabaseConnection::dateExtractSql
File
- drivers/
database_mysql/ database.inc, line 700 - Database interface code for MySQL database servers.
Class
Code
public function dateExtractSql($field, $extract_type) {
// Note there is no space after FROM to avoid db_rewrite problems
// see http://drupal.org/node/79904.
switch (strtoupper($extract_type)) {
case 'DATE':
return $field;
case 'YEAR':
return "EXTRACT(YEAR FROM($field))";
case 'MONTH':
return "EXTRACT(MONTH FROM($field))";
case 'DAY':
return "EXTRACT(DAY FROM($field))";
case 'HOUR':
return "EXTRACT(HOUR FROM($field))";
case 'MINUTE':
return "EXTRACT(MINUTE FROM($field))";
case 'SECOND':
return "EXTRACT(SECOND FROM($field))";
// ISO week number for date.
case 'WEEK':
return "WEEK($field, 3)";
case 'DOW':
// MySQL returns 1 for Sunday through 7 for Saturday, PHP date
// functions use 0 for Sunday and 6 for Saturday.
return "INTEGER(DAYOFWEEK($field) - 1)";
case 'DOY':
return "DAYOFYEAR($field)";
}
// An unknown function.
return FALSE;
}