public function datetimeIntervalClause($date, $interval)
    {
        $trans = array(
            'year' => 'yy',
            'month' => 'mm',
            'day' => 'dd',
            'hour' => 'hh',
            'minute' => 'mi',
            'second' => 'ss',
        );

        $singularinterval = preg_replace('/(year|month|day|hour|minute|second)s/i', '$1', $interval);

        if (
            !($params = preg_match('/([-+]\d+) (\w+)/i', $singularinterval, $matches)) ||
            !isset($trans[strtolower($matches[2])])
        ) {
            user_error('datetimeIntervalClause(): invalid interval ' . $interval, E_USER_WARNING);
        }

        if (preg_match('/^now$/i', $date)) {
            $date = "CURRENT_TIMESTAMP";
        } elseif (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/i', $date)) {
            $date = "'$date'";
        }

        return "CONVERT(VARCHAR, DATEADD(" . $trans[strtolower($matches[2])] . ", " . (int)$matches[1] . ", $date), 120)";
    }