Reputation: 3847
Okei,, so I am trying to retrieve some info from my database with a +/- 10 days setting.
Values:
Event.start_date = y-m-d
Event.end_date = y-m-d
My.date = y-m-d
$conditions["My.date >="] = date( 'Y-m-d');
$conditions["My.date -10 >="] = Event.start_date;
$conditions["My.date +10 >="] = Event.end_date;
Any suggestions how I can achive this?
Upvotes: 1
Views: 55
Reputation: 3847
This is how :)
$conditions = array(
"OR" => array(
array('My.date BETWEEN DATE_ADD(?, INTERVAL -10 DAY) AND ?' => array($data['Event']['start_date'],$data['Event']['end_date'])),
array('My.date BETWEEN ? AND DATE_ADD(?, INTERVAL 10 DAY)' => array($data['Event']['start_date'],$data['Event']['end_date']))
)
);
Upvotes: 0
Reputation: 14361
Try this in your query
If you are checking against today's date:
WHERE startDate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 10 DAY)
If you are checking against your own end date:
WHERE startDate BETWEEN endDate() AND DATE_ADD(endDate(), INTERVAL 10 DAY)
For going back - 10 days
WHERE startDate BETWEEN DATE_ADD(startDate(), INTERVAL -10 DAY) AND endDate()
Please adjust logic according to your needs.
Upvotes: 3