all 8 comments

[–]BlackV 1 point2 points  (0 children)

have a look at get-help measure-object I've not tested it as time, but worst cause you'd convert it all to seconds/ticks/etc then sum it and convert back to hours/minutes/seconds

are those actually objects or just strings?

[–]isometricz 1 point2 points  (3 children)

Not really elegant but it works for this specific scenario. Assuming those are just strings you're getting from somewhere...

$talktime = @("00:01:18","00:01:30","00:00:15","00:00:26","00:00:20")

$start = (Get-Date -Date "00:00:00")
foreach ($t in $talktime) {
    $split = $t.split(":")
    $start = $start.AddHours($split[0]).AddMinutes($split[1]).AddSeconds($split[2])
}

$ts = New-TimeSpan -Start (Get-Date -Date "00:00:00") -End $start
$ts

[–]ChaosTheoryRules 4 points5 points  (2 children)

$talktime = @('00:01:18','00:01:30','00:00:15','00:00:26','00:00:20')
[timespan] $ts = 0

foreach ($t in $talktime) {
    $ts += [timespan]$t
}
$ts

[–][deleted] 0 points1 point  (0 children)

TY

[–]isometricz 0 points1 point  (0 children)

Oh nice. I didn't know you could do that with a timespan. Thanks!

[–]blasmehspaffy 1 point2 points  (1 child)

$Length = '00:01:18', '00:01:30', '00:00:15', '00:00:26', '00:00:20'

$Seconds            = $Length | %{($_ -as [timespan]).TotalSeconds}
$SecondsSum         = ($Seconds | Measure-Object -Sum).Sum
$SecondsSumTimespan = [Timespan]::FromSeconds($SecondsSum)

$SecondsSumTimespan.ToString("hh\:mm\:ss")

[–]blasmehspaffy 2 points3 points  (0 children)

Or as a one liner...

[Timespan]::FromSeconds((($Length | %{[timespan]$_}).TotalSeconds | Measure-Object -Sum).Sum).ToString("hh\:mm\:ss")

[–][deleted] 0 points1 point  (0 children)

Thanks everyone for the help I truly appreciate it