Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What is best way to calculate age
Message
From
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:
01155815
Views:
23
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform