Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Code for Months between two dates?
Message
De
12/01/2001 07:31:23
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00462838
Message ID:
00462850
Vues:
14
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform