I am trying to grab all SQL entries WHERE Day difference between current date and expiration date is < than 4 days
My first approach was following:
$sql_i_requested = "SELECT *, (To_days(date_return)-TO_DAYS(NOW())) as daydif FROM ".$tbl_name."
WHERE (status!='completed' AND status!='canceled')
AND owner_id=".$owner_id."
AND daydif < 4
ORDER BY date_created DESC";
My second aproach is (according to SQL DateDifference in a where clause):
$sql_i_requested = "SELECT * FROM ".$tbl_name."
WHERE (status!='completed' AND status!='canceled')
AND owner_id=".$owner_id."
AND date_return > DateAdd(day, -3, getdate())
ORDER BY date_created DESC";
Neither of them work, so how do I select FROM table WHERE day_difference between "date_return" and now()
is less than 4 days?
EDIT:
changed
AND daydif < 4
to
AND (To_days(date_return)-TO_DAYS(NOW())) < 4
and now it's working. Anyway, maybe you guys could suggest other solutions.