Tuesday, 15 June 2010

php - select from table where day difference is less than some number -



php - select from table where day difference is less than some number -

i trying grab sql entries day difference between current date , expiration date < 4 days

my first approach following:

$sql_i_requested = "select *, (to_days(date_return)-to_days(now())) daydif ".$tbl_name." (status!='completed' , status!='canceled') , owner_id=".$owner_id." , daydif < 4 order date_created desc";

my sec aproach (according sql datedifference in clause):

$sql_i_requested = "select * ".$tbl_name." (status!='completed' , status!='canceled') , owner_id=".$owner_id." , date_return > dateadd(day, -3, getdate()) order date_created desc";

neither of them work, how select table day_difference between "date_return" , now() less 4 days?

edit:

changed

and daydif < 4

to

and (to_days(date_return)-to_days(now())) < 4

and it's working. anyway, maybe guys suggest other solutions.

using datediff

where datediff(date_return, now()) < 4

php sql

No comments:

Post a Comment