Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code for Months between two dates?
Message
From
12/01/2001 07:31:23
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00462838
Message ID:
00462850
Views:
16
Hi Jim,
I like your function, but i thinks is missing something ... and i made a little change.
For the example :
Date 1 = 2000-01-12
Date 2 = 2000-02-11

He may want to know how many months have between Dates, and the true answer is "0", but "1" it true if he only want to know months without looking to the days.
tlCheckDays is a paramter that he sets to controls the situation.

.
* Calculates the months between two dates
LPARAMETERS tdDate1, tdDate2, tlCheckDays
LOCAL lnMonths, ldStart, ldEnd

ldStart = MIN(tdDate1,tdDate2) && Get the earlier date
ldEnd = MAX(tdDate1,tdDate2) && Get the later date
lnMonths = 0

* As long as the earlier date is less than the later date
DO WHILE ldStart < ldEnd
lnMonths = lnMonths + 1
ldStart = GOMONTH(ldStart,1)
ENDDO
IF tlCheckDays AND DAY(ldStart) > DAY(ldEnd)
lnMonths = lnMonths - 1
ENDIF
RETURN lnMonths
.

Nuno Brito
Nuno Brito
Previous
Reply
Map
View

Click here to load this message in the networking platform