php - compare date with database (birthdate) -
so have row called birthday in database value of let's 2001-04-25 (date type). , want see if it's user birthday. current month , day:
$monthday_today = date('m-d');
and query:
$query = "select * users date_format(birthday, '%m-%d')=".$monthday_today;
but doesn't works, thoughts?
you need quote $monthday_today value.
you query (if output it) this:
select * users date_format(birthday, '%m-%d') != 04-2014
but not correct sql query, query should this:
select * users date_format(birthday, '%m-%d') != '04-2014'
the simple solution be:
$query = "select * users date_format(birthday, '%m-%d')!="."'".$monthday_today."'";
the solution use parameterized prepared statements either positional or named parameters:
$query = "select * users date_format(birthday, '%m-%d') != ?";
or
$query = "select * users date_format(birthday, '%m-%d') != :monthday_today";
you don't need quote parameterized prepared statements because infer (deduce) if quoting necessary or not type of variable.
Comments
Post a Comment