Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Days between months not dates
Message
From
26/11/2009 06:04:43
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Days between months not dates
Miscellaneous
Thread ID:
01436643
Message ID:
01436643
Views:
107
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
Next
Reply
Map
View

Click here to load this message in the networking platform