Q:

How to combine simple math with strings with php in MySQL query

I want to add a filter to my MySQL query based on users birthday.
Providing:
$cur_year = 2012
$cur_month = 07
$cur_day = 18

How do I do the difference $cur_year - $minAge and then display -07-19 (month and day)
I'm trying this:
`Birthday` < $cur_year - $minAge'-$cur_month-$cur_day'

A:

I'm reasonably certain you are trying to do something like this:
$minAge = 18;

$query = "
  SELECT
    `somecol`, `someothercol`,
    IF(DATE_ADD(`Birthday`, INTERVAL ".((int) $minAge)." YEAR) < NOW(), 1, 0) AS `isOldEnough`
  FROM `tablename`
  WHERE `somecol` = 'someval'
";

In each returned row, the isOldEnough key in the result will contain 1 if the user is 18 years old, or 0 if they aren't.

