Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is best way to calculate age
Message
From
21/09/2006 09:15:05
 
 
To
21/09/2006 08:45:30
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01155605
Message ID:
01155939
Views:
23
>Fabio, why do you expect 17 days when 15 is correct
>1988,2,29 is the last day in february in 1988 + 15 days yields the 14th
>
>Cetin is right, you are wrong!
>
>
>Peter
>

Peter, when you say:
age is 18 years, 6 months and 15 days,

the 15 days of life are the first days or the last days of life ?

For me they are the last days, and therefore they must be counted in the 2006.

otherwise you have to say
age is: 15 days 6 months and 18 years.

>
>
>>>>We need totals of clients by age bracket. What is the best way to calculate the age? Right now, we are using:
>>>>
>>>>INT((DATE() - a.dob) / 365)
>>>>
>>>>But that doesn't take into consideration leap years (which could be significant for someone over 90 years old). Any suggestions? Should I just use:
>>>>
>>>>INT((DATE() - a.dob) / 365.25)
>>>>
>>>>Or is there a better (more accurate) way?
>>>>
>>>>Thanks,
>>>>Doug
>>>
>>>**********************************************************************************
>>>*  Class.............: Viscollect_utility
>>>*  Author............: Cetin Basoz
>>>*  Project...........: Visual Collections
>>>*  Created...........: 11/02/2004  10:52:17
>>>*  Copyright.........: (c) Jzanus, LTD, 2004
>>>*  Major change list.:
>>>*  					 : ART - Moved Function to common_utiity.prg from viscollect_utility.prg
>>>
>>>*!*	oAge = createobject('Age')
>>>*!*	ldBirth = {^1961/1/19}
>>>*!*	ldTarget = date() && How old is he today.
>>>*!*	oAge.CalcAge(ldBirth, ldTarget)
>>>*!*	? oAge.Years, oAge.Months, oAge.Days
>>>
>>>define class age as relation
>>>	Years=0
>>>	Months=0
>>>	Days=0
>>>	procedure CalcAge
>>>	lparameters tdBirth, tdTarget
>>>	local ldTemp, ldBirth, lnDrop
>>>	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
>>>
>>
>>The so easy age by to calculate is not.
>>
>>Your trust should stagger :)
>>
>>
>>WITH CREATEOBJECT("age")
>>
>>	.CalcAge({^1988/2/29} ,  {^2006/9/14 })
>>	
>>	CLEAR
>>
>>	*	Observed : 18,6,15
>>	*	Expected : 18,6,17
>>
>>	? .Years , .Months , .Days
>>	* CHECK with the correct definition Age = (((Birth+Y)+M)+D)
>>	?  GOMONTH(GOMONTH({^1988/2/29},.Years*12),.Months)+.Days
>>	* CHECK with a bad definition
>>	?  GOMONTH({^1988/2/29},.Years*12+.Months)+.Days
>>	* none definition can return {^2006/9/14 }
>>ENDWITH
>>	
>>
>>**********************************************************************************
>>*  Class.............: Viscollect_utility
>>*  Author............: Cetin Basoz
>>*  Project...........: Visual Collections
>>*  Created...........: 11/02/2004  10:52:17
>>*  Copyright.........: (c) Jzanus, LTD, 2004
>>*  Major change list.:
>>*  					 : ART - Moved Function to common_utiity.prg from viscollect_utility.prg
>>
>>*!*	oAge = createobject('Age')
>>*!*	ldBirth = {^1961/1/19}
>>*!*	ldTarget = date() && How old is he today.
>>*!*	oAge.CalcAge(ldBirth, ldTarget)
>>*!*	? oAge.Years, oAge.Months, oAge.Days
>>
>>define class age as relation
>>	Years=0
>>	Months=0
>>	Days=0
>>	procedure CalcAge
>>	lparameters tdBirth, tdTarget
>>	local ldTemp, ldBirth, lnDrop
>>	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
>>
Previous
Reply
Map
View

Click here to load this message in the networking platform