Jump to content

trying to add time values (not in milliseconds)


gcue
 Share

Recommended Posts

i have time values that i would like to aggregate and am trying to find the best way to do this.. any ideas?

$item1 = "00:00:02"
$item2 = "00:00:01"

$total = $item1 + $item2

MsgBox(0,"",$total)

_DateAdd() could be used for that. AFAIK there is no function to add up hh:mm:ss values directly.

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Try this:

$item1 = "00:00:02"
$item2 = "00:00:01"
MsgBox(0,"Value",AddTime($item1,$item2))

Func AddTime($TIME1,$TIME2)
Local $MIN_CARRY = 0,$HOUR_CARRY = 0
$SPLIT1 = StringSplit($TIME1,":")
$SPLIT2 = StringSplit($TIME2,":")
$SEC = Number($SPLIT1[3]) + Number($SPLIT2[3])
While $SEC >= 60
    $SEC -= 60
    $MIN_CARRY += 1
WEnd
$MIN = Number($SPLIT1[2]) + Number($SPLIT2[2])
$MIN += $MIN_CARRY
While $MIN >= 60
    $MIN -= 60
    $HOUR_CARRY += 1
WEnd
$HOUR = Number($SPLIT1[1]) + Number($SPLIT2[1])
$HOUR += $HOUR_CARRY
If $HOUR >= 24 Then
    Return "ERROR"
Else
    $HOUR = String($HOUR)
    $MIN = String($MIN)
    $SEC = String($SEC)
    If StringLen($HOUR) < 2 Then $HOUR = "0" & $HOUR
    If StringLen($MIN) < 2 Then $MIN = "0" & $MIN
    If StringLen($SEC) < 2 Then $SEC = "0" & $SEC
    Return $HOUR & ":" & $MIN & ":" & $SEC
EndIf
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...