gcue Posted February 4, 2009 Share Posted February 4, 2009 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) Link to comment Share on other sites More sharing options...
rudi Posted February 4, 2009 Share Posted February 4, 2009 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 More sharing options...
Andreik Posted February 4, 2009 Share Posted February 4, 2009 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 More sharing options...
gcue Posted February 4, 2009 Author Share Posted February 4, 2009 perfect!!! many many thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now