douzong5473 2019-01-05 01:22
浏览 48
已采纳

如何修复PHP中的Datediff语法

I calling out value from database where Datediff from followupdate and NOW().

If the followupdate is happened before NOW(), it works, but if followupdate comes after NOW() it does't work.

This is my focus line. $re1 = mysqli_query($conn,"select booking.* from booking WHERE DATEDIFF( NOW(),followupdate ) <= 3 ;");

already try switch NOW() and followupdate back and forward.

date_default_timezone_set("Asia/Kuala_Lumpur");

$re1 = mysqli_query($conn,"select booking.* from booking WHERE DATEDIFF( NOW(),followupdate  ) <= 3 ;");
if(mysqli_num_rows($re1) > 0){
    while ($row = mysqli_fetch_array($re1) ){


     print "<tr style=\"\">      <td>".$row['booking_id']."</td>
";

p/s: assumed the followupdate is always larger than NOW()

Give me a simple code that can describe what to do. thanks

  • 写回答

2条回答 默认 最新

  • doushou9028 2019-01-05 02:15
    关注

    If you have already tried swapping positions and still getting failures I suggest you use

    WHERE ABS( DATEDIFF( followupdate, NOW() ) ) <= 3
    

    so the date difference can be either positive or negative and your comparison will continue to operate.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效