Converting HH:MM:SS string to Seconds Integer

I need to covert a HH:MM:SS string to Seconds as Integer

Thanks
Dan
DigitalDan3Asked:
Who is Participating?
 
jake072Commented:
Is the input as a string?  Is it always in the format HH:MM:SS ?

If so, then try something like this:

Dim iSeconds as Integer = strInput.SubString(0, 2) * 60 * 60 + strInput.SubString(3, 2) * 60 + strInput.SubString(6, 2)

Where strInput is the Input string, and is always HH:MM:SS...

So you could have something like (for input string):

00:00:01, 12:00:01, etc....

Let me know if you need further help.

Jake
0
 
DigitalDan3Author Commented:
What if the input was a date and time and I wanted to convert to seconds.  Is there not a Framework method to convert HH:MM:SS to seconds?
0
 
jake072Commented:
Ok then,

Dim dteTime As DateTime = [Parse your string into a DateTime...]
Dim lngSeconds As Long = dteTime.Ticks * TimeSpan.TicksPerSecond

Voila!

Let me know if you need more help,

Jake

0
 
jake072Commented:
Whoops!!!

Should've been a divide operation, not a multiplication!  My apologies!

Anyways, that will give you the seconds expressed by the date time...  (So it will also take into account the seconds for the date: "The value of this property [Ticks] is the number of 100-nanosecond intervals that have elapsed since 12:00 A.M., January 1, 0001")...  This may not be what you want, but there it is.

Jake
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.