1

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;

有什么建议我可以做到这一点吗?

4

2 回答 2

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()

请根据您的需要调整逻辑。

于 2012-12-03T12:33:55.827 回答
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']))
            )
);
于 2012-12-04T13:07:50.080 回答