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!

DateTime Difference

Status
Not open for further replies.

davman2002

Programmer
Nov 4, 2002
75
0
0
US
I am trying to calculate the value of time remaining time between three variables. For example: If I have 32 hours and 30 minutes and that time was calculated at 12:00 PM and I want to know how much time it would take before I reach 40 hours. How do I do a date difference between 40 hours and 32.3 hours which would be 7.3 not 7.7 (7.7 is what I am getting) and then add that time (7.3) to the current time in a datetime box?
 
I must not understand your question because this is what i come up with and surely you would have already figured this out.
Code:
int startMins = ( 60 * 32) + 30;
int targetMins = ( 60 * 40);
int diffMins = targetMins - startMins;

cout << diffMins / 60 << &quot; hours &quot; << diffMins % 60 << &quot; minutes &quot; << endl;
which outputs:
7 hours 30 minutes

so if you take a date time value of 12:00 p.m. and add 7 hours and 30 minutes to it you will have your adjusted time, yes?

-pete
 
why don't you use C function given in msdn &quot;difftime&quot; which would give the diffrence between 2 times

double difftime( time_t timer1, time_t timer0 );
difftime returns the elapsed time in seconds, from timer0 to timer1. The value returned is a double-precision floating-point number.

Hope it hepls you

 
Palbano

Must have been late, That makes sense now. Thanks.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top