Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Years and months between two dates
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00160317
Message ID:
00161876
Views:
16
As an exerceise too, I wrote the following code. Maybe the dummiest version possible. :) But it is good in terms of code readability... :)
lparameters tdDate1, tdDate2, tnYears, tnMonths, tnDays

local ldEarly, ldLate, ldSaved

ldEarly = min(tdDate1, tdDate2)
ldLate = max(tdDate1, tdDate2)

ldSaved = ldEarly
tnYears = 0
do while ldEarly <= ldLate
	tnYears = tnYears + 1
	ldEarly = gomonth(ldEarly, 12)
enddo
tnYears = tnYears - 1
ldEarly = gomonth(ldSaved, tnYears * 12)

ldSaved = ldEarly
tnMonths = 0
do while ldEarly <= ldLate
	tnMonths = tnMonths + 1
	ldEarly = gomonth(ldEarly, 1)
enddo
tnMonths = tnMonths - 1
ldEarly = gomonth(ldSaved, tnMonths)

tnDays = 0
do while ldEarly < ldLate
	tnDays = tnDays + 1
	ldEarly = ldEarly + 1
enddo
tnDays = tnDays

?tnYears, tnMonths, tnDays
Vlad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform