I have DOB stored in dB as 2 digit value (IE: 98,99,05…), how I can compare it to today’s date to get age?
Tried different variations, even converted today’s date to 2 digit but I cannot compare it…
TIMESTAMPDIFF(year, d.dob, DATE_FORMAT(CURDATE(), '%y')) AS age
Thanks in advance!
3
Answers
You can use something like next query:
just decide what the max age allowed.
Play with query here
As you told that dob is ranges from 1970 to 2010, and is stored as a DATE type column, you can compare it with today’s date to calculate the age by adjusting the year component of each date. Here’s how you can do it:
Assuming the oldest supported birth year is 1970, you can approximate age best by assuming the person was born in the middle of the year and doing some simple math:
But without birth month and day, you cannot calculate exact age.