CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2006
    Posts
    143

    Difference between two time values

    Hi, I want to get the difference between two time values expressed in HH:MM:SS:MilliSecond in all the four components of time. ie. Time1 = 12:30:45:345 , Time2= 12:45:48:400. I want the want the difference between these two values in terms of hour, minute, second and millisecond. The COleDateTime class supports only upto second and not millisecond though it has a constructor that acceps a SYSTEMTIME structure as argument. But I dont know how to get the millisecond value from COleDateTime even if I passed a SYSTEMTIME into it. Looks like the COleDateTime does not have a GetMilliSecond() functiion though you can subtract two COleDateTime values to get the difference.

  2. #2
    Join Date
    Oct 2009
    Location
    Germany / Bremen
    Posts
    7

    Re: Difference between two time values

    you have to:
    1. convert both times to milliseconds
    2. subtract them
    3. convert the resulting value to your old time-structure

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Difference between two time values

    Or you can implement your own class that represents a time span with the desired precision.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jun 2006
    Posts
    143

    Re: Difference between two time values

    Thank you.

  5. #5
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Difference between two time values

    Or you can use boost posix time library. You'll have to link against the data time library, though - some boost libraries only have header files, so they're easy to use, but the date time library is not one of them. If you're not using boost already in your project, that could be quite a lot of work.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

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

Featured