I'm attempting to select records from my postgresql database using php
based on whether someone is at least 17 years old on the date of a particular visit.


My sql is:

$db_sql = "SELECT * from list WHERE ((visit_date - birth_date) >= 17)'"
$db_result = db_exec($db_sql)
$num = pg_num_rows($db_result);
for($i = 0; $i < $num; $i++)
  {
  $data = pg_num_rows($db_result,$i)
  $visit_date = $data["visit_date"];
  $birth_date = $data["birth_date"];
  echo "Visit date[$visit_date]  Birth date[$birth_date]";
  }

The problem I'm having is that the the query is returning results for some people with ages < 17 (most of them are correct, just a couple of incorrect ones interspersed with the correct ones that are over 17)?

For example, my output contains:

Visit date[2004-07-14]  Birth date[2004-02-19]
and
Visit date[2004-08-11]  Birth date[2003-04-21]

which are clearly people who are < 17.


Any suggestions on how to track down this problem or rework the query so it always works correctly? If I reverse the query and look for people < 17, I don't get any that are older than 17.


Thanks,
Bruce


---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to