How do I retrieve all 60 years old above using birth_date in PHP PDO?

Ask a question
1

I want to display all the customer where the age is 60 years old above by using the birth_date. The type of bith_date is date. This is the format of the birth_date-> 1999-03-12. Can somebody help me with my problem?

$sql = "SELECT * FROM `tbl_beneficiary` INNER JOIN tbl_barangay ON 
        tbl_beneficiary.barangay_id = tbl_barangay.barangay_id WHERE 
        tbl_beneficiary.is_active = 'No' AND (DATEDIFF(NOW(), 
        tbl_beneficiary.birth_date) <= 60) ORDER BY 
        tbl_beneficiary.beneficiary_id";
offer bounty
add comment

1 Answer

2

I think this must work as you expect
$sql = "SELECT * FROM tbl_beneficiary INNER JOIN tbl_barangay ON tbl_beneficiary.barangay_id = tbl_barangay.barangay_id WHERE tbl_beneficiary.is_active = 'No' AND (DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(), tbl_beneficiary.birth_date)), "%Y") >= 60) ORDER BY tbl_beneficiary.beneficiary_id";

add comment

Your Answer