I must calculate numbers of days totals and for each period
Now there are 4 periods but can be more periods
I have two date: dDateFrom and DateTO and I must check if this interval ( dDateFrom and DateTO ) is on each period and calculate the number of days
How I can resolve ?
I explain you
I have to calculate how many days there are compared to the period table shown above
that is, for example:
if I have
dDateFrom 07.07.2018
DateTO 14.08.2018
I would have 39 days of which
low 0 days first record on table
low 0 days second record on table
Average 19 days 3th record on table
high 20 days 4th record on table
I tried but not run
Code: Select all
Function Test()
Local aListini:= {}
Local nYear :=year(date())
SET DATE ITALIAN
SET DATE FORMAT "dd-mm-yyyy"
USE LISTINI ALIAS LI
DO While !LI->(eof())
AaDd(aListini,{ (LI->CHECK_IN),(LI->CHECK_OUT),LI->GUEST })
LI->(dbskip())
ENDDO
XBROWSER aListini
dDateFrom:= Ctod( "7/07/2018")
dDateTo := Ctod("14/08/2018")
Calcolo_Giorni(dDateFrom,dDateTo,aListini)
RETURN NIL
Function Calcolo_Giorni(dDateFrom,dDateTo,aListini)
Local n
Local aDays:= array(len(alistini))
For n= 1 to Len(alistini)
IF dDateFrom >= cTOD(aListini[n][1] ) .and. dDateTo <= cTOD(aListini[n][2] )
adays[n] :=1 + ( dDateTo - dDateFrom )
endif
Next
xbrowser adays
return nil