;;FUNCTION         DeltaTime() - DEPRECATED in ITCG CODING - SEE TIMEDIFF() 
;; 
;;ACTION           Calculates the time difference between two given times 
;; 
;;AUTHOR           Jochen Polster 
;; 
;;VERSION          1.1 - 2004/04/07 
;;                  Fixed for NoVarsInStrings = ON 
;;                  Milliseconds can now be omitted (if Zero) in one of the strings 
;; 
;;SYNTAX           DeltaTime(Start,End) 
;; 
;;PARAMETERS       Start - Required - String 
;;                  -  value representing the starttime - Format hh:mm:ss[:ms] 
;; 
;;                 End - Required - String 
;;                  -  value representing the ending time - Format hh:mm:ss[:ms] 
;; 
;;REMARKS          Highest possible delta Value is 23:59:59:999 ! 
;;                 If the diff gets higher , the result will be incorrect. 
;; 
;;RETURNS          The difference between Start - and Endtime in 'hh:mm:ss[:ms]' 
;; 
;;DEPENDENCIES     KiXtart 4.0 
;; 
;;EXAMPLES         call "PATH\DeltaTime.udf" 
;;                 $start = @time + ':' + @msecs 
;;                 for $i = 0 to 15000 
;;                     $ = @scriptdir 
;;                 next 
;;                 $end = @time + ':' + @msecs 
;;                 ? 'Start time  : $start' ? 
;;                 ? 'End time    : $end' ? 
;;                 $Duration = DeltaTime($start,$end) 
;;                 ? 'Duration    : $Duration' ? ? 
;; 
;;                 $start = "21:59:59" ? 'Backup Started  : $start' ? 
;;                 $end   = "01:00:01" ? 'Backup Ended    : $end' ? 
;;                 $d = DeltaTime($start,$end) 
;;                 ? 'Backup Duration : $d' ? 
;; 
;;                 get $k 
; 
function DeltaTime($Start,$End)
    dim $, $s, $e, $MS_Start, $MS_End, $S_Start, $S_End, $total, $deltaH, $deltaM, $deltaS, $deltaMS, $i
    $s = split($Start,":")
    $e = split($End,":")
    if ubound($s) <> ubound($e)
        if ubound($s) > ubound($e)
            redim preserve $e[ubound($e)+1]
            $e[ubound($e)] = "000"
        else
            redim preserve $s[ubound($s)+1]
            $s[ubound($s)] = "000"
        endif
    endif
    for $i = 0 to ubound($s)
        $s[$i] = val($s[$i])
        $e[$i] = val($e[$i])
    next
    if ubound($s) = 3
        $MS_Start = $s[3] + $s[2] * 1000 + $s[1] * 60000 + $s[0] * 3600000
        $MS_End   = $e[3] + $e[2] * 1000 + $e[1] * 60000 + $e[0] * 3600000
        select
            case $MS_Start > $MS_End
                $total = 86400000 - ($MS_Start - $MS_End)
            case $MS_Start < $MS_End
                $total = $MS_End - $MS_Start
            case 1
                $DeltaTime = "00:00:00:000" exit 1
        endselect
        $deltaH  = $total / 3600000
        $total   = $total - $deltaH * 3600000
        $deltaM  = $total / 60000
        $total   = $total - $deltaM * 60000
        $deltaS  = $total / 1000
        $deltaMS = $total - $deltaS * 1000
    else
        $S_Start = $s[2] + $s[1] * 60 + $s[0] * 3600
        $S_End   = $e[2] + $e[1] * 60 + $e[0] * 3600
        select
            case $S_Start > $S_End
                $total = 86400 - ($S_Start-$S_End)
            case $S_Start < $S_End
                $total = $S_End - $S_Start
            case 1
                $DeltaTime = "00:00:00" exit 1
        endselect
        $deltaH = $total / 3600
        $total  = $total - $deltaH * 3600
        $deltaM = $total / 60
        $deltaS = $total - $deltaM * 60
    endif
    $deltaH = right('0' + $deltaH, 2)
    $deltaM = right('0' + $deltaM, 2)
    $deltaS = right('0' + $deltaS, 2)
    if ubound($s) = 3
        $deltaMS = right('00' + $deltaMS, 3)
        $DeltaTime = "" + $deltaH + ":" + $deltaM + ":" + $deltaS + ":" + $deltaMS
    else
        $DeltaTime = "" + $deltaH + ":" + $deltaM + ":" + $deltaS
    endif
endfunction