Justin Dominic
Justin Dominic

Reputation: 1237

how to find age in zend query from date of birth

i am tryin to find differnce in current time and date of birth can anyone help me

to find the age from an mysql query in zend framwork the age should be greater than 21

       $date = Zend_Date::now(); 
   $dob = $post['dob'];

   $age = $date ->sub($dob);
       $age->toString(Y);

can this work anyone know any simple method thanks for helping

Upvotes: 0

Views: 548

Answers (1)

Dmitry Z.
Dmitry Z.

Reputation: 434

What about extracting years from database. If you using mysql, try to use this query

SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(dob)), '%Y')+0 AS age FROM people;

It’ll also work with pre and post-epoch dates.

If this method will not solve your problem, try to read about Zend_Date comparison but instead of if ($date->compare(10, Zend_Date::MINUTE) == -1) use if ($date->compare(21, Zend_Date::YEAR) == -1)

Upvotes: 3

Related Questions