dp926460 2018-09-02 18:10
浏览 28
已采纳

之间的当前日期不能在php查询中工作

I have mysql table with columns section, is_date_based (Yes/No values), date_start, date_end and showhide

query is

$query = "select * from tabele where section='Festival Wish' and ((is_date_based='No') OR (is_date_based='Yes' and (CURDATE() between date_start and date_end ))) and showhide='0' order by sort_order asc";

condition 1. : Now if is_date_based='No' and showhide='0', row should be displayed...And IT IS WORKING....

condition 2. : But if id_date_based='Yes' and if current date-time is between date_start and date_end and showhide='0' , then and then only row should be displayed...

........

but unfortunately, condition 2 is not working even with required values and data in mysql table...

mysql table structure is

section       is_date_based  showhide    date_start          date_end
Festival Wish   Yes            0       2018-09-01 05:00:00  2018-09-05 11:30:00
Festival Wish   No             0       0000-00-00 00:00:00  0000-00-00 00:00:00

Here second record is shown, properly with above query, but first record is not shown even when current date is between date_start and date_end...

  • 写回答

1条回答 默认 最新

  • dst2017 2018-09-02 18:33
    关注

    could be you need now() and not curdate(.

    curdate() return date eg 2018-09-01 now() return date an time 2018-09-05 20:34:00 ..

    could be also you need time adjiust for your sample the 11:30 is past

    $query = "select * 
            from tabele 
            where section='Festival Wish' 
            and ( (is_date_based='No') 
                  OR (is_date_based='Yes' and (NOW() between date_start and date_end ))) 
            and showhide='0' order by sort_order asc";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度