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:
00161942
Vues:
19
>< g > Check: {12/1/97} and {11/30/98}. This is one year later than the previous test... :)
>
Hi Vlad,

I get 0 years, 11 months, 29 days, which is correct isn't it? December 1 to November 1 is 11 months, November 1 to November 30 is 29 days.

Anyway, I did find a different problem. If the year of the earlier date is Fe. 29, you get an invalid date. So...
* 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
pnyears = 0
DO WHILE YEAR(GOMONTH(ldearly, pnyears * 12)) < YEAR(ldlate)
  pnyears = pnyears + 1
ENDDO
ldbefore = GOMONTH(ldearly, pnyears * 12)
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
IF GOMONTH(ldnewdate, pnmonths) > ldlate
  pnmonths = pnmonths - 1
ENDIF
ldnewdate = GOMONTH(ldnewdate, pnmonths)
pndays = ldlate - ldnewdate
RETURN
I know some of the above will look familiar (referencing your other post).< 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