I am trying to do a search query (using pdo php and mysql) between a date range which is between (date-7days) and (date-1day) using DATE_SUB() on both so for example:
end_date is 2013-03-26
search between 2013-03-19 and 2013-03-25 `
The below query however is using the first date_sub(7 day interval) but ignoring the second (date_sub(1 day interval) so its searching between 2013-03-19 and 2013-03-26.
$sevd_query = "
SELECT
booking_id,
DATE_FORMAT(start_date, '%e/%c') AS s_d,
DATE_FORMAT(end_date, '%e/%c') AS e_d
FROM
bsi_bookings as bb
INNER JOIN
bsi_reservation as br ON bb.booking_id=br.bookings_id
WHERE
bc.c_id=:c_id AND
:day BETWEEN DATE_SUB(bb.end_date, INTERVAL 7 DAY) AND DATE_SUB(bb.end_date, INTERVAL 1 DAY)
";
Can anyone please help? I've been trying to fix this for a week now with no luck
Copyright Notice:Content Author:「odd_duck」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15649466/mysql-search-query-between-date-sub-and-date-sub-error