Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculate the age
Message
From
02/06/2019 16:29:41
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
02/06/2019 00:25:07
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Miscellaneous
Thread ID:
01668878
Message ID:
01668880
Views:
77
Likes (1)
>how is the faster way to calculate the age in VFP?
>
>eg.
>born: 02-05-2000
>today: 02-06-2019
>result: 19 years 1 month
>
>Thanks in advance
>
>Jerry Yang
Function AgeSimple(tdBirthDate)
    local lnAge
    lnAge = year(date()) - year(m.tdBirthDate)
    if gomonth(m.tdBirthDate, 12 * m.lnAge) > date()
       m.lnAge = m.lnAge - 1
    endif 
   return m.lnAge
endfunc
If you want to know how many years, months and days (which may be important, say for medical applications):
clear
tdTarget = DATE()
tdBirth = {^1988/2/29}
oAge = CalcAge(tdBirth, tdTarget)
? oAge.Years, oAge.Months, oAge.Days
tdBirth = {^1988/2/29}+1

oAge = CalcAge(tdBirth, tdTarget)
? oAge.Years, oAge.Months, oAge.Days

Procedure CalcAge
  Lparameters tdBirth, tdTarget
  Local ldTemp, ldBirth, lnDrop, loAge, lnSelect
  loAge = CreateObject('empty')
  AddProperty(m.loAge,'Months',0)
  DO WHILE GOMONTH(m.tdBirth,loAge.Months+1) < m.tdTarget
  	loAge.Months = loAge.Months + 1 
  ENDDO
  AddProperty(m.loAge, 'Days', m.tdTarget - GOMONTH(m.tdBirth,loAge.Months))
  AddProperty(m.loAge, 'Years', INT(loAge.Months / 12))
  loAge.Months = loAge.Months % 12
  Return loAge
Endproc
Ç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