Okei ,,所以我试图通过+/- 10天的设置从我的数据库中检索一些信息。
值:
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;
我有什么建议可以实现这个目标吗?
答案 0 :(得分:3)
在您的查询中尝试此操作
如果您要查看今天的日期:
WHERE startDate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 10 DAY)
如果您要检查自己的结束日期:
WHERE startDate BETWEEN endDate() AND DATE_ADD(endDate(), INTERVAL 10 DAY)
回去 - 10天
WHERE startDate BETWEEN DATE_ADD(startDate(), INTERVAL -10 DAY) AND endDate()
请根据您的需要调整逻辑。
答案 1 :(得分:0)
这是:)
$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']))
)
);