0

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...

1
  • 1
    Are these date fields or varchar? Commented Jul 27, 2012 at 12:51

3 Answers 3

5
$sql = "SELECT * FROM `meetings` 
        WHERE date('2012-07-28') 
              between `recurring_st_date` AND `recurring_ed_date`";
Sign up to request clarification or add additional context in comments.

2 Comments

You may need an explicit conversion of the string '2012-07-28' to date. At least it would be more portable that way.
the conversion is not necessary to make it work. But being portable is a good point.
2
`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')

Comments

0

Remove the backslashes

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.