Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dateAdd() fix #138

Merged
merged 2 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/DatabaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ public function currentTimestamp()
* Prefixing the interval with a - (negative sign) will cause subtraction to be used.
* Note: Not all drivers support all units.
*
* @param mixed $date The date to add to. May be date or datetime
* @param string $date The db quoted string representation of the date to add to. May be date or datetime
* @param string $interval The string representation of the appropriate number of units
* @param string $datePart The part of the date to perform the addition on
*
Expand All @@ -701,7 +701,7 @@ public function currentTimestamp()
*/
public function dateAdd($date, $interval, $datePart)
{
return trim("DATE_ADD('" . $date . "', INTERVAL " . $interval . ' ' . $datePart . ')');
return 'DATE_ADD(' . $date . ', INTERVAL ' . $interval . ' ' . $datePart . ')';
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Postgresql/PostgresqlQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,9 @@ public function processLimit($query, $limit, $offset = 0)
*
* Prefixing the interval with a - (negative sign) will cause subtraction to be used.
*
* @param datetime $date The date to add to
* @param string $interval The string representation of the appropriate number of units
* @param string $datePart The part of the date to perform the addition on
* @param string $date The db quoted string representation of the date to add to
* @param string $interval The string representation of the appropriate number of units
* @param string $datePart The part of the date to perform the addition on
*
* @return string The string with the appropriate sql for addition of dates
*
Expand All @@ -725,10 +725,10 @@ public function dateAdd($date, $interval, $datePart)
{
if (substr($interval, 0, 1) !== '-')
{
return "timestamp '" . $date . "' + interval '" . $interval . ' ' . $datePart . "'";
return "timestamp " . $date . " + interval '" . $interval . " " . $datePart . "'";
}

return "timestamp '" . $date . "' - interval '" . ltrim($interval, '-') . ' ' . $datePart . "'";
return "timestamp " . $date . " - interval '" . ltrim($interval, '-') . " " . $datePart . "'";
}

/**
Expand Down