MichaelRed: I am fairly new to Tek-Tips although I am not fairly new to programming(34 years) Before you start bad mouthing code from someone trying to provide assistance to someone here in this forum, maybe you should truly take a look at the suggestion that was made and learn something. I usually don't say anything in these forums when there are opposing viewpoints; but when you start to make derogatory and arrogant remarks that are patently wrong, I believe clarification is warranted so less experienced individuals are not inappropriately influenced by your bias.. My suggestion is that you test the expression against a datafile of birthdates and see how many are wrong.
AGE: CInt( (DateDiff('d',tblYourTable.Birth_Date,Date())/365.25) -0.5)
The DateDiff code while simplistic, does work well and is extremely accurate. It is more than a simplistic DateDiff calculation. I am well aware of the downfall of just doing a datediff on “d”(days) calculation between a birthdate and todays date and then dividing by 325.25. Surely, this will be off half of the time when the resulting real number has a remainder that is .50 or greater. Yes, someone that calculates at 54.5160848733744 will come out as 55 years old if that is all that this "simplistic code" did to the calculation. But, it does more. I am aware that the rounding up factor will create a 50% error rate if we left it at that. You should LOOK at the code suggested and see that before I performed the CInt function, which is where the rounding takes place, I subtracted .5 years from the initial calculation. This would put the above real number at 54.0160848733744. The real number does not round up but has the decimal portion truncated off through the rounding down with a result of 54 - which is the SIMPLE and CORRECT age calculation for a birthdate of 11/21/1947. This works for all dates where the decimal portion calculates at .5 or greater. For those that calculate less than .5 (54.4996577686516) the same subtraction of .5 years takes place which lowers the real number below the correct age to 53.9996577686516 which when rounded up during the CInt function gives us the CORRECT age of 54 once again.(DOB 11/27/1947).. Now the only issue that should be brought to bear here is the Leap Century adjustment. If it were necessary to perform celestial calculation of the expansion of the universe then it would make sense to put this adjustment into play. But, since we are only calculating how old someone is I felt it was uncessary.
Last line of your post which I thought was quite telling:
“There is never time to do it right but there is always time to do it over”
Where here is mine:
“There is never anything wrong with a simplistic approach to a problem if the results are correct.”
CinS: My apologies for this posting in your question thread. I felt that it was necessary to speak up. There are many ways to calculate the Age of someone. There have been other posts that have provided functions and expressions that all perform the same basic calculation. This is just one of the methods that I use and it has served me well. Yes, it works and you can use it with confidence.
Bob Scriver