如何修复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
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.
DATEDIFF(date1, date2)
returns the result of date1 - date2
in days. If date2
is later, the result is negative.
SELECT DATEDIFF( DATE('2019-12-1'), NOW());
returns 330 today, on 2019-1-5.
You propably want:
WHERE DATEDIFF( followupdate, NOW() ) <= 3