Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Years and months between two dates
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00160317
Message ID:
00161822
Vues:
33
>It doesn't work for many dates. Check 12/1/97 and 11/30/97.
>
Hi Vlad,

Acck, you're right. I thought I checked that possibility. Well, obviously it was one I overlooked. Here's the modified code:
* FUNCTION YrsMosDays.prg

LPARAMETERS pddate1, pddate2, pnyears, pnmonths, pndays

LOCAL ldearly, ldlate, ldbefore, lnyears, ldnewdate
ldearly = MIN(pddate1, pddate2)
ldlate = MAX(pddate1, pddate2)
* Create a date made of the later year and
* the month and day of the earlier date
ldbefore = CTOD(ALLTRIM(STR(MONTH(ldearly))) + "/" +;
  ALLTRIM(STR(DAY(ldearly))) + "/" + ;
  ALLTRIM(STR(YEAR(ldlate))))
pnyears = YEAR(ldlate) - YEAR(ldearly)
IF ldbefore > ldlate
  pnyears = pnyears - 1
ENDIF
ldnewdate = GOMONTH(ldearly, pnyears * 12)
pnmonths = MONTH(ldlate) - MONTH(ldnewdate)
IF pnmonths < 0
  pnmonths = pnmonths + 12
ELSE
  IF ldbefore > ldlate AND pnmonths = 0
    pnmonths = 11
  ENDIF
ENDIF
* This is the modification
IF GOMONTH(ldnewdate, pnmonths) > ldlate
  pnmonths = pnmonths - 1
ENDIF
ldnewdate = GOMONTH(ldnewdate, pnmonths)
pndays = ldlate - ldnewdate
RETURN
How's that? It's worked with everything I've tested. Let me know if you can manage to find a flaw.< g >
George

Ubi caritas et amor, deus ibi est
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform