Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculating Ages
Message
From
12/12/2002 11:23:17
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
12/12/2002 01:42:17
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00732144
Message ID:
00732266
Views:
20
>Is there a simple formula for calculating someone's age in years and months as of today's date?
>
>I could work one out myself but if there is one available then I might as well use it!
>
>Thank you
>
>Bob
dBirth = {^1961/1/19}
oAge = Createobject("age")
*oAge.CalcAge(dBirth, dTarget)
oAge.CalcAge(dBirth)
? oAge.Years, oAge.Months, oAge.Days
? Gomonth(tdBirth,oAge.Years*12+oAge.Months)+oAge.Days

Define Class age As Relation
  Years=0
  Months=0
  Days=0
  Procedure CalcAge
  Lparameters tdBirth, tdTarget
  Local ldTemp, ldBirth, lnDrop
  tdTarget = iif(empty(tdTarget),date(),tdTarget)
  If tdBirth > tdTarget
    ldTemp = tdTarget
    tdTarget = tdBirth
    tdBirth = ldTemp
  Endif
  ldBirth = Date(Year(tdTarget),Month(tdBirth),Day(tdBirth))
  lnDrop = 0
  If Empty(ldBirth) && leap case
    ldBirth = Date(Year(tdTarget),3,1)
    lnDrop = Iif(Month(tdTarget)<=2,0,1)
  Endif
  With This
    .Years = Year(tdTarget) - Year(tdBirth) - (Iif(ldBirth > tdTarget,1,0))
    .Months = (Month(tdTarget) - Month(tdBirth) + 12 - ;
      (Iif(Day(tdBirth)>Day(tdTarget),1,0)))%12
    .Days = tdTarget - Gomonth(tdBirth,.Years*12+.Months) - lnDrop
  Endwith
Endproc
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform