Saturday, March 17, 2012

calculate age in mysql query


if you want to calculate the age of members or user then it is very easy you do not need to call a php function to do, because mysql query will do it for you, check and test this query i hopefull this will not disappoint you,
so enjoy

select *,DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(tablename.fieldname, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(tablename.fieldname, '00-%m-%d')) AS age from tablename

No comments :

Post a Comment