I thought SQL Server's DATEDIFF was a neat function to calculate a person's age at a given moment. But I was wrong.
It's important that I get the correct age of a person at a given time comparing that time's date to the date of birth. I'm given read only access. This means I can't create a function, so I have to implement it in the query.
So far came up with CAST(DATEDIFF(day, dateOfBirthColumn, otherDateCoumn) / 365.25 AS Integer) AS Age. This gives me a pretty exact age, but not the correct age in some cases due to the fact that the division by 365.25 isn't actually correct.
Any suggestions on how to calculate the exact age between two dates?
I'm querying a SQL Server 2005 database. Maybe unneccesary to say, but why didn't the engineers at MS thought of this...?
Aucun commentaire:
Enregistrer un commentaire