Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is best way to calculate age
Message
 
 
To
21/09/2006 01:06:36
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:
01155938
Views:
27
Fabio,

I was thinking about this problem and I'm not sure we really have to arrive to the same point as we started. At least Rick Borup's reasoning seems a valid one.

I need to read his code and readme first and I'm going to add Reverse date to his test, so I can see how accurate the calculation is. I was also thinking of trying 02/29/1904 to 02/29/2004, etc...

>>Thanks. Do you know how to correct the problem?
>
>the time of the game has expired.
>
>This is the solution:
>
>WITH CREATEOBJECT("age")
>
>	CLEAR
>	
>	.CalcAge({^1988/2/29} ,  {^2006/9/14 })
>		
>	? .Years , .Months , .Days
>
>	* CHECK with the correct definition Age = (((Birth+Y)+M)+D)
>	* forward is precise
>	?  GOMONTH(GOMONTH({^1988/2/29},.Years*12),.Months)+.Days
>	* backward is approx
>	? GOMONTH(GOMONTH({^2006/9/14 } - .Days, -.Months), - .Years*12)
>
>	* infact
>	* respect to YMD Feb 28/29 are equals !!
>	
>	.CalcAge({^1988/2/28} ,  {^2006/9/14 })
>	
>	? .Years , .Months , .Days
>	
>ENDWITH
>
>define class age as relation
>
>	Years	= NULL
>	Months	= NULL
>	Days 	= NULL
>	
>	procedure CalcAge
>	lparameters tdBirth, tdTarget
>
>	PRIVATE dateStep
>
>	WITH m.This
>		.Years = YEAR(m.tdTarget)-YEAR(m.tdBirth)
>
>		dateStep = GOMONTH(m.tdBirth,.Years*12)
>		
>		IF m.dateStep > m.tdTarget
>			.Years = .Years - 1
>			dateStep=GOMONTH(m.tdBirth,.Years*12)
>		ENDIF
>		
>		.Months = (MONTH(m.tdTarget) - MONTH(m.dateStep)) % 12
>		
>		IF GOMONTH(m.dateStep,.Months) > m.tdTarget
>			.Months = .Months -1
>		ENDIF
>		
>		.Days = m.tdTarget - GOMONTH(m.dateStep,.Months)
>	ENDWITH
>	
>	ENDPROC
>	
>ENDDEFINE
>
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform