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";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂