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条)

报告相同问题?