function _signup_date_sql_math in Signup 5.2
Same name and namespace in other branches
- 6.2 includes/date.inc \_signup_date_sql_math()
Helper function to handle date math across DB types.
This can be removed once date_api_sql.inc revision 1.4.2.35 is widely available in an official release.
Parameters
$field: The field to be adjusted.
$direction: Either ADD or SUB.
$count: The number of values to adjust.
$granularity: The granularity of the adjustment, should be singular, like SECOND, MINUTE, DAY, HOUR.
1 call to _signup_date_sql_math()
- _signup_date_reminder_sql in includes/
date.5x-2.inc
File
- includes/
date.5x-2.inc, line 250 - Code required to support version 5.x-2.* of the CCK date field module.
Code
function _signup_date_sql_math($field, $direction, $count, $granularity) {
$granularity = strtoupper($granularity);
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
if ($direction == 'ADD') {
return "DATE_ADD({$field}, INTERVAL {$count} {$granularity})";
}
else {
return "DATE_SUB({$field}, INTERVAL {$count} {$granularity})";
}
case 'pgsql':
$granularity .= 'S';
if ($direction == 'ADD') {
return "({$field} + INTERVAL '{$count} {$granularity}')";
}
else {
return "({$field} - INTERVAL '{$count} {$granularity}')";
}
}
return $field;
}