猿问

如何以3天为间隔显示结束日期的数据?

我必须在数据库中添加一些条目才能向用户发送通知,但条件看起来像这样,


这是我的结束日期06-05-2019,现在的当前日期是03-05-2019或01-05-2019,我想在结束日期的3天之前发送通知到实际的结束日期。就像,我的结束日期是06-05-2019某些事件的话,我想在日期发送的通知04-05-2019,05-05-2019,06-05-2019。


我的cakePHP查询代码在这里:


$offer_notify_second = $this->NotificationStore->find('all', array(

                'contain' => array(),          

                'fields' => array('NotificationStore.id','NotificationStore.role_id','NotificationStore.user_id','NotificationStore.notification_type','NotificationStore.notification_app_display_type','NotificationStore.link','NotificationStore.offer_id','NotificationStore.offer_type'), 

                'conditions' => array('DATE_SUB(NotificationStore.end_date, INTERVAL 3 DAY)' => date('Y-m-d'), 'NotificationStore.user_id' => $this->request->data['user_id'], 'NotificationStore.notification_type' => OFFER_NOTIFICATION),

            ));

```


沧海一幻觉
浏览 168回答 1
1回答

阿波罗的战车

我将共享原始查询片段,您可以将其映射到CAKEPHPWHERE NotificationStore.end_date >= DATE(NOW() + INTERVAL 3 DAY) + INTERVAL 0 SECOND  AND NotificationStore.end_date >= CURDATE();第1部分NotificationStore.end_date >= DATE(NOW() + INTERVAL 3 DAY) + INTERVAL 0这意味着,现在+ 3天应该大于结束日期,例如当前时间为2019-05-02,接下来的3天为2019-05-05,然后条件失败当前条件为2019-05-03,接下来的3天为2019-05-06,然后条件成功第2部分NotificationStore.end_date >= CURDATE()这意味着,end_date必须大于cur_date才能满足即将到来的3天范围,否则在有第一个条件的情况下它将始终大于。
随时随地看视频慕课网APP
我要回答