MySQL - Search Query between DATE_SUB() AND DATE_SUB() Error
NickName:odd_duck Ask DateTime:2013-03-27T07:41:57

MySQL - Search Query between DATE_SUB() AND DATE_SUB() Error

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

More about “MySQL - Search Query between DATE_SUB() AND DATE_SUB() Error” related questions

MySQL - Search Query between DATE_SUB() AND DATE_SUB() Error

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

Show Detail

MySql query syntax error DATE_SUB

what's wront with this query? SELECT * FROM containmentTracker WHERE reviewDate < NOW() AND reviewDate > DATE_SUB(NOW(), INTERVAL 10 YEARS) I've tried in several way but every time I use

Show Detail

Error in MySQL to HiveQL Conversion including DATE_SUB and INTERVAL

I am trying to convert the query written in MySQL to HiveQL The part of query giving me error is : WHERE 1 = 1 AND table1.incoming_date >= DATE_SUB(DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE()) -...

Show Detail

MySql How to use DATE_SUB in Between clause

I am having problem while using DATE_SUB for DateTime fields. I want to use query like this: SELECT * FROM SellBySalesman WHERE userid=37 and sellingDate BETWEEN CURDATE() AND

Show Detail

Illuminate database query with date_sub

I'm struggling with a query using the Illuminate database query builder. When I use the query the result is not as I expected. When using the query from the querylog directly with mysql cli, I get ...

Show Detail

Issue with DATE_SUB() and MIN()

I'm trying to get all the rows from 10 days before the last matching property_id. The query below is what I came up with but the HAVING part is not working. SELECT * FROM tab t WHERE t.property...

Show Detail

Mysql DATE_SUB(NOW(), INTERVAL 365 DAY) MYSQL ERROR

SELECT DATE_FORMAT(created_date,'%W') as day, DATE_FORMAT(created_date,'%d') as dat, DATE_FORMAT(created_date,'%M') as mon, created_date as dated, SUM(price) AS amount FROM `order_invoice` BETWEEN

Show Detail

MYSQL - Select Query Between DATE_ADD and DATE_SUB

I have a booking in my mysql booking table bookings as below: start_date = 2013-03-04 end_date = 2013-03-08 I want to check if a particular day (in this case 2013-03-04) falls between the start a...

Show Detail

DATE_SUB problem

my code: $song = mysql_query("SELECT COUNT(*) FROM `".$this->prefix."playlist` WHERE `time` > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 20 MICROSECOND) AND `long` < DATE...

Show Detail

mysql match by date using date_sub

I have this mysql query SELECT * FROM all_sent_Orders a WHERE a.nachforschungCompletedOn IS NULL AND CASE WHEN a.lastMessageSent IS NOT NULL AND a.lastResponse IS NULL THEN date(da...

Show Detail