close all
clear
set date british
set century on
? NoMonths(ctod("01/01/2004"),ctod("21/01/2004"))
? NoMonths(ctod("01/01/2003"),ctod("21/01/2004"))
function NoMonths
parameters eDate,lDate
private eDate,lDate,myValue,tDate
myValue = 0
if lDate < eDate
tDate = eDate
eDate = lDate
lDate = tDate
endif
if lDate <> eDate
if Month(eDate) = Month(lDate) .and. Year(eDate) = Year(lDate)
** calculate no days
myValue = (lDate-eDate)/DaysInMonth(eDate)
else
myMonthsAvg = (DaysInMonth(eDate)+DaysInMonth(lDate))/2
myValue = ((DaysInMonth(eDate)-Day(eDate))+Day(lDate))/myMonthsAvg
myValue = myValue + IIF(DAY(LDate)>=DAY(EDate),0,-1)+(YEAR(LDate)-YEAR(EDate))*12+MONTH(LDate)-MONTH(EDate) - 1
endif
endif
return(myValue)
Function DaysInMonth
Parameter mDate
Private mDate,mDays,mDateFmt
mDateFmt = Set("Date")
set Date to British
mDays = Day(Ctod("1/"+alltrim(str(Month(mDate+32),2,0))+"/"+alltrim(str(Year(mDate+32),4,0)))-1)
Set Date to (mDateFmt)
return(mDays)