function DateSqlHandler::sql_where_date in Date 8
Creates a where clause to compare a complete date field to a date value.
Parameters
string $type: The type of value we're comparing to, could be another field or a date value.
string $field: The db table and field name, like "$table.$field".
string $operator: The db comparison operator to use, like '='.
int $value: The value to compare the extracted date part to, could be a field name or a date string or NOW().
Return value
string SQL for the where clause for this operation.
File
- date_api/
lib/ Drupal/ date_api/ DateSqlHandler.php, line 533
Class
- DateSqlHandler
- A class to manipulate date SQL.
Namespace
Drupal\date_apiCode
function sql_where_date($type, $field, $operator, $value, $adjustment = NULL) {
$type = strtoupper($type);
if (strtoupper($value) == 'NOW') {
$value = $this
->sql_field('NOW', $adjustment);
}
elseif ($type == 'FIELD') {
$value = $this
->sql_field($value, $adjustment);
}
elseif ($type == 'DATE') {
$date = new DrupalDateTime($value, drupal_get_user_timezone(), DATE_FORMAT_DATETIME);
if (!empty($adjustment)) {
date_modify($date, $adjustment . ' seconds');
}
// When comparing a field to a date we can avoid doing timezone
// conversion by altering the comparison date to the db timezone.
// This won't work if the timezone is a field instead of a value.
if (empty($this->db_timezone_field) && empty($this->local_timezone_field) && $this->db_timezone_field != $this->local_timezone_field) {
$date
->setTimezone(timezone_open($this->db_timezone));
$this->local_timezone = $this->db_timezone;
}
$value = "'" . $date
->format(DATE_FORMAT_DATETIME, TRUE) . "'";
}
if ($this->local_timezone != $this->db_timezone) {
$field = $this
->sql_field($field);
}
else {
$field = $this
->sql_field($field, 0);
}
return "{$field} {$operator} {$value}";
}