Frank
Frank

Reputation: 2357

mysql query for filtering specific rows by date condition in php?

I have a table 'meetings' which has following fields

id   recurring_start_date  recurring_end_date (Both are date fields)
1.    2012-07-22             2012-07-25
2.    2012-07-27             2012-08-05
3.    2012-07-26             2012-08-26
4.    2012-07-23             2012-10-23
5.    2012-08-24             2012-11-24
6.    2012-09-12             2012-10-19
7.    2012-07-28             2012-07-29

I want to filter those rows by sql query which contain '2012-07-28' date between start-end recurring dates range and including start n end recurring date.

We know result will be 2nd, 3rd, 4th, 7th rows.
But how do i run this query in php.

I tried this, but its not working.

$sql = "
    SELECT * 
    FROM 
        `meetingss` 
    WHERE 
        `recurring_st_date` >= \'2012-07-28\' 
        AND `recurring_ed_date` <= \'2012-07-28\' 
    ";

May be am going wrong , may be supplied date condition wrong.
Any good suggestion my mates to do this. Thanks...

Upvotes: 0

Views: 5494

Answers (3)

juergen d
juergen d

Reputation: 204746

$sql = "SELECT * FROM `meetings` 
        WHERE date('2012-07-28') 
              between `recurring_st_date` AND `recurring_ed_date`";

Upvotes: 5

Tchoupi
Tchoupi

Reputation: 14681

Remove the backslashes

`recurring_st_date` >= '2012-07-28' 
AND `recurring_ed_date` <= '2012-07-28' 

Upvotes: 0

Ozerich
Ozerich

Reputation: 2000

`recurring_st_date` >= STR_TO_DATE('2012-07-28', '%Y-%m-%d') AND 
`recurring_ed_date` <= STR_TO_DATE('2012-07-28', '%Y-%m-%d')

Upvotes: 2

Related Questions