This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Time difference.

I wan to find the time difference between Current time and the Previous time.

In my project i maintain some time interval and that interval is checked by converting the both previous and current time to entire seconds and find the difference.

The difference is checked with the interval in the program.

I have written the program to find the difference but for example let me say my previous time - 23:59:30 and the current time is - 00:00:54 then when i try to find the difference like, time = current time - previous time i get some wrong value due to overflow.

Bcos the each second the previous and current time is converted to total seconds and its difference is only checked.

can any suggest me how this can be rectifed?

Parents
  • Your problem is because you have only time and not date;
    therefore, you have to assume that the date must have changed if the times are in the "wrong order"

    if( current_time >= previous_time )
    {
       // both times are from the same day
    }
    else
    {
       // previous_time is later than current time!
       // Must assume that previous time refers to
       // a previous day...
    }
    
    
    

Reply
  • Your problem is because you have only time and not date;
    therefore, you have to assume that the date must have changed if the times are in the "wrong order"

    if( current_time >= previous_time )
    {
       // both times are from the same day
    }
    else
    {
       // previous_time is later than current time!
       // Must assume that previous time refers to
       // a previous day...
    }
    
    
    

Children
No data