Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to determine difference between 2 times

Status
Not open for further replies.

ShawnCoutts

Programmer
Jul 4, 2006
74
CA
Just so that everyone knows, i am not using Cbuilder for this. My IDE does not have date/timediff functionality.

I am having some difficulty determining how to get the difference between 2 times. The times are stored as hex values. When I treat the times normally, as integers, and convert them into seconds, I get one value. When I convert the times from hex to integer and then convert them into seconds, I get an entirely different value.

My two test values that I am using are:

8:42:25 and 9:25:12. (these are on a 24 hour clock)

and my two values from each equation are:

2567s and 1841s

the correct value is 2567s

TIA
Shawn
 
Why don't you just use the formula that gives the right results?

Or am I missing something? Maybe you could tell us exactly how the time values are stored.

 
>> The times are stored as hex values.
Stored In what type of variable, one of the flavors of int? If so, they're not stored as hex values, they're stored as binary values.

>> When I convert the times from hex to integer and then convert them into seconds, I get an entirely different value.

Saying that you're converting from hex to integer makes no sense. If you mean from hex to decimal (base 10), both are stored identically (it's all binary) unless you're storing them as strings.

For example:
int i = 0x10; // the binary value in i is 00010000
int i = 16; // the binary value in i is 00010000

They're identical. 16 is 16 whether I use it's decimal or it's hex representation.

Or am I, like TonyGroves, missing something?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top