Converting HH:MM:SS string to Seconds Integer

Posted on 2006-05-15
Last Modified: 2008-02-26
I need to covert a HH:MM:SS string to Seconds as Integer

Question by:DigitalDan3
    LVL 14

    Accepted Solution

    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.


    Author Comment

    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?
    LVL 14

    Expert Comment

    Ok then,

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


    Let me know if you need more help,


    LVL 14

    Expert Comment


    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.


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now