Hi,
In an Excek sheet, time for each row is in the format hh:mm:ss
How do I convert it into seconds when I sum the column.
Also, when I sum it does it exceed 24 hours? How to handle that?
thank you,
Hi,
In an Excek sheet, time for each row is in the format hh:mm:ss
How do I convert it into seconds when I sum the column.
Also, when I sum it does it exceed 24 hours? How to handle that?
thank you,
Hi @A_Learner
First you should Use an Assign activity to convert the time string into total seconds in a loop and add the ‘Seconds’ column using the Add Data Column activity before the loop.
row(“Seconds”) = TimeSpan.Parse(row(“Time”).ToString()).TotalSeconds
Then you can calculate all seconds like below:
totalSeconds = DataTable.AsEnumerable().Sum(Function(row) Convert.ToDouble(row(“Seconds”)))
Finally convert totalSeconds back to ‘hh:mm:ss’ format (even if it exceeds 24 hours).This will display the total time in a 24+ hour format:
formattedTime = $“{Math.Floor(totalSeconds / 3600)}:{Math.Floor((totalSeconds Mod 3600) / 60)}:{totalSeconds Mod 60}”
Hope this helps,
Regards.
you can try this
timespanvariable = Timespan.FromSeconds(dt.AsEnumerable().Sum(Function(row) TimeSpan.Parse(row(“Time”).ToString()).TotalSeconds))
as hours can be more than 24 also when you sum it would display hours accordingly…
cheers
So @Anil_G it is not giving the seconds. For example if my time is “00:10:01” I would expect to see 601 seconds. It is only showing 00:10:01
Thank you
HI,
How about the following?
TimeSpan.Parse("00:10:01").TotalSeconds
Please note that the above input string must be convertible to TimeSpan. If the string cannot be converted to TimeSpan, some additional expression is required.
Regards,
Only this would give seconds
Doublevariable =dt.AsEnumerable().Sum(Function(row) TimeSpan.Parse(row(“Time”).ToString()).TotalSeconds)
Or do you mean in each row also you need seconds or only total?
Cheers
Only Total. Thank you.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.