Information générale
Titre:
Days between months not dates
Hi,
I found this program below which works except the variable endofmonth gives me the wrong number of days. It gives me 18 days when it should give me 0 years, 11 months and 28 days but I get 18 days.
Thanks in advance
* BTWNDATE.PRG
startdate = {19/02/2008} && Thisform.dStart.value
enddate = {18/02/2009} &&Thisform.dend.value
IF startdate ‘&greaterthan’ enddate
WAIT WINDOW "Start date must " + CHR(13) ;
+ "be earlier than End date"
RETURN
ENDIF
PRIVATE precmpdate, vyears, vmonths, vdays
precmpdate={}
vyears=0
vmonths=0
vdays=0
nTotdays = 0
* Calculate:
* endofmonth is the last day of month prior to month of enddate
*
endofmonth = CTOD(ALLTRIM(STR(MONTH(enddate))) + '/' + "01" + '/' + ;
ALLTRIM(STR(YEAR(enddate)))) - 1
*
IF MONTH(startdate) ‘&lessthan’= MONTH(enddate)
vyears = YEAR(enddate) - YEAR(startdate)
IF DAY(startdate) ‘&lessthan’= DAY(enddate)
vmonths = MONTH(enddate) - MONTH(startdate)
vdays = DAY(enddate) - DAY(startdate)
nTotdays = (enddate) - (startdate)
ELSE
IF MONTH(startdate) = MONTH(enddate)
vyears = vyears - 1
ENDIF
vmonths = MOD(MONTH(enddate) - MONTH(startdate) - 1 + 12, 12)
vdays = endofmonth - precmpdate + DAY(enddate)
nTotdays = (enddate) - (startdate)
ENDIF
ELSE
vyears = YEAR(enddate) - YEAR(startdate) - 1
IF DAY(startdate) ‘&greaterthan’ DAY(enddate)
vmonths = MONTH(enddate) - MONTH(startdate) + 12 - 1
vdays = endofmonth - precmpdate + DAY(enddate)
nTotdays = (enddate) - (startdate)
ELSE
vmonths = MONTH(enddate) - MONTH(startdate) + 12
vdays = DAY(enddate) - DAY(startdate)
nTotdays = (enddate) - (startdate)
ENDIF
ENDIF
Clear
= Messagebox('Values are'+ CHR(13) + ;
' Years: ' + STR(vyears) + CHR(13) + ;
' Months: ' + STR(vmonths) + CHR(13) + ;
' Days: ' + STR(vdays) + CHR(13) + ;
' Total number of Days: ' + STR(nTotdays) + CHR(13) + ;
CHR(13) + ;
' Between ' + DTOC(startdate) + CHR(13) +;
' and ' + DTOC(enddate))
RETURN
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement