Silvio,
this function calculates everything from given Start Day / time to End Day / time :
Only a Time-calculation :
Sample :
tStart := '12:45:12'
tEnd := '10:20:30'
dStart := Date()
dEnd := Date()
( we add a Day, because time-end < time-start )
IF VAl( SUBSTR( tEnd, 1, 2 ) ) < VAl( SUBSTR( tStart, 1, 2 ) )
dEnd++
ENDIF
aDiff := ELAPSED( dStart, dEnd, tStart, tEnd )
The Function returns :
--------------------------
aDiff[1,1] -> Days
aDiff[2,1] -> Hours
aDiff[3,1] -> Minutes
aDiff[[4,1] -> Seconds
MsgAlert( "Hours : " + STR(aDiff[2,1]) + CRLF + ;
"Minutes : " + STR(aDiff[3,1]) + CRLF + ;
"Seconds : " + STR(aDiff[4,1]) , "12:45:12 to 10:20:30 " )
Code: Select all
FUNCTION ELAPSED(dStart, dEnd, cTimeStart, cTimeEnd)
LOCAL nTotalSec, nCtr, nConstant, nTemp, aRetVal[4,2]
IF ! ( VALTYPE(dStart) $ 'DC' )
dStart := DATE()
ELSEIF VALTYPE(dStart) == 'C'
cTimeStart := dStart
dStart := DATE()
ENDIF
IF ! ( VALTYPE(dEnd) $ 'DC' )
dEnd := DATE()
ELSEIF VALTYPE(dEnd) == 'C'
cTimeEnd := dEnd
dEnd := DATE()
ENDIF
IF( VALTYPE(cTimeStart) != 'C', cTimeStart := '00:00:00', )
IF( VALTYPE(cTimeEnd) != 'C', cTimeEnd := '00:00:00', )
nTotalSec := (dEnd - dStart) * 86400 + ;
VAL(cTimeEnd) * 3600 + ;
VAL(SUBSTR(cTimeEnd,AT(':', cTimeEnd)+1,2)) * 60 + ;
IF(RAT(':', cTimeEnd) == AT(':', cTimeEnd), 0, ;
VAL(SUBSTR(cTimeEnd,RAT(':', cTimeEnd)+1))) - ;
VAL(cTimeStart) * 3600 - ;
VAL(SUBSTR(cTimeStart,AT(':', cTimeStart)+1,2)) * 60 - ;
IF(RAT(':', cTimeStart) == AT(':', cTimeStart), 0, ;
VAL(SUBSTR(cTimeStart,RAT(':', cTimeStart)+1)))
nTemp := nTotalSec
FOR nCtr = 1 to 4
nConstant := IF(nCtr == 1, 86400, IF(nCtr == 2, 3600, IF( nCtr == 3, 60, 1)))
aRetVal[nCtr,1] := INT(nTemp/nConstant)
aRetval[nCtr,2] := nTotalSec / nConstant
nTemp -= aRetVal[nCtr,1] * nConstant
NEXT
RETURN aRetVal
Best Regards
Uwe