1 date_sql_handler.inc | date_sql_handler::sql_date_math($field, $direction, $count, $granularity) |
Adjusts a field value by time interval.
Parameters
string $field: The field to be adjusted.
string $direction: Either ADD or SUB.
int $count: The number of values to adjust.
string $granularity: The granularity of the adjustment, should be singular, like SECOND, MINUTE, DAY, HOUR.
File
- core/
modules/ date/ views/ date_sql_handler.inc, line 176 - SQL helper for Date API.
Class
- date_sql_handler
- A class to manipulate date SQL.
Code
function sql_date_math($field, $direction, $count, $granularity) {
$granularity = strtoupper($granularity);
switch ($direction) {
case 'ADD':
return "DATE_ADD($field, INTERVAL $count $granularity)";
case 'SUB':
return "DATE_SUB($field, INTERVAL $count $granularity)";
}
return $field;
}