Calculate age based on date of birth.

Hi,

In a tabel I want to calculate the age of people based on the date of birth.

Today it is the 5th of november 2004.
When the date of birth is the 6th of november 1965, the age should be 38.
But it is calculated as 39.

procedure TDM.TRelatiesCalcFields(DataSet: TDataSet);
begin
  If DateToStr(DM.TRelaties.FieldByName('Geboortedatum').AsDateTime)<>'30-12-1899' then
    DM.TRelaties.FieldByName('Leeftijd').asInteger:=YearsBetween(Now,DM.TRelaties.FieldbyName('Geboortedatum').asdatetime)
  else
    DM.TRelaties.FieldByName('Leeftijd').asInteger:=0;
end;

Can anybody finetune my calculation?

Thanks Stef
Stef MerlijnDeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mokuleCommented:
Hi,
Try
YearsBetween(DateOf(Now),DateOf(DM.TRelaties.FieldbyName('Geboortedatum').asdatetime))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
moorhouselondonCommented:
The following depends on how you populate your table, and whether you are using the BDE.

You don't have the Regional settings set for the wrong country perchance?  (Or ditto with the BDE, but not both)

If this is the UK (with US date format) then you would get:-

11 May 2004
11 June 1965

which is 39 complete years.

0
BlackTigerXCommented:
works ok on my machine... maybe stripping off the time as mokule suggested

YearsBetween(DateOf(Now),DateOf(DM.TRelaties.FieldbyName('Geboortedatum').asdatetime))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.