Results 1 to 3 of 3

Thread: subtracting time

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    Posts
    184

    subtracting time

    I'm having trouble calculating the correct time laps.

    start_time = DateTime.Now
    (program code)
    Dim processing_time As TimeSpan = DateTime.Now - start_time
    msgbox(processing_time.Minutes)

    start - 3/13/2013 7:49:30 PM
    end - 3/13/2013 10:57:10 PM

    My result was 7 mins. It seems like my code is not subtracting the hours. How do I correct this?

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: subtracting time

    Try
    Code:
    msgbox(processing_time.TotalMinutes)
    ..and about the subtraction i would use Subtract() method
    Code:
    Dim MinCount As Double = DateTime.Now.Subtract(start_time).TotalMinutes
    Last edited by jcis; Mar 14th, 2013 at 10:33 AM.

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: subtracting time

    How about using a Stopwatch

    Code:
            Dim stpw As New Stopwatch
            stpw.Reset()
            stpw.Restart()
            'code to be timed
            stpw.Stop()
            Debug.WriteLine(stpw.Elapsed.ToString)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width