select * from patient where age as datediff(pdob,’2022-06-11′)>=75;
why is this query is giving an empty set?
My question is:- Find all the patients who can avail of senior citizen discount.
>Solution :
The problem of DATE_DIFF is that it outputs the difference in days. If you want a difference in years, you can use DATE_ADD:
SELECT *
FROM patient
WHERE DATE_ADD(pdob, INTERVAL 75 YEAR) < '2022-06-11'
Check the demo here.
Note: if you really want to use DATE_DIFF, you need to transform 75 years into days and use that value.