为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
沧海一幻觉 2021-05-20 18:15:18
我必须在数据库中添加一些条目才能向用户发送通知,但条件看起来像这样,这是我的结束日期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),            ));```
查看完整描述

1 回答

?
阿波罗的战车

TA贡献1862条经验 获得超6个赞

我将共享原始查询片段,您可以将其映射到CAKEPHP

WHERE 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天范围,否则在有第一个条件的情况下它将始终大于。


查看完整回答
反对 回复 2021-05-28
  • 1 回答
  • 0 关注
  • 167 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信