Click here to Skip to main content
16,020,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

I am currently busy on an import of data in which i convert duration(time format hh:mm:ss) to seconds as i do a compare on my data in seconds

The issue i am having is when converting the duration to timespan of totalseconds
i am getting an error if the duration exceeds 23:59:59

How would i be able to convert my time (e.g. 68:25:35) to seconds?

What I have tried:

This is the code i am currently running
e.g. duration in file = '68:25:35'
duration = FileValue(count)
duration = TimeSpan.Parse(duration).TotalSeconds
Posted
Updated 31-Oct-16 2:59am
Comments
Philippe Mori 31-Oct-16 8:55am    
You have to write your own code. TimeSpan requires the number of day so your file should contains 2.20:25:35 instead if you want to use TimeSpan.

1 solution

Convert yourself:
C#
var s = duration.Split(':'); // given "68:25:35" as a string
var totalsecs = int.Parse(s[0])*3600 + int.Parse(s[1])*60 + int.Parse(s[2]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900