I am trying to calculate the age of a person given a particular date in the past; let's just say '02-01-2020' for this example.
I have something like this:
SELECT person.name,
CASE
WHEN DATEADD(YEAR, DATEDIFF(YEAR, person.birthdate, '02-01-2020'), person.birthdate) < '02-01-2020'
THEN DATEDIFF(YEAR, person.birthdate, '02-01-2020')-1
ELSE DATEDIFF(YEAR, person.birthdate, '02-01-2020')
END AS calculated_age,
FROM PersonTable
[...]
I don't think this works for potential birthdates that fall after '02-01-2020', and I was wondering if there is just a better way to do this?