difftime problem

C

collinm

hi


Code:
parseDate(&prod->tmbEndRun, date_rtu);
parseTime(&prod->tmbEndRun, prod->htime_rtu_fin);
printf("end %s\n", prod->htime_rtu_fin);

return me

05/06/10
end 14:24:28


Code:
parseDate(&prod->tmbStartRun, date_rtu);
parseTime(&prod->tmbStartRun, hactual_time);

return me

05/06/10
start 14:31:03

now i would like to have duration between us....

Code:
prod->timeEndRun=mktime(&prod->tmbEndRun);
prod->timeStartRun=mktime(&prod->tmbStartRun);
prod->stopRun = difftime(prod->timeStartRun, prod->timeEndRun);

printf("stop run: %d %ld %ld\n",prod->stopRun, prod->timeStartRun,
prod->timeEndRun);

that return me
stop run: -3205 1118428263 1118431468

why prod->timeStartRun (14:31:03) is smaller then prod->timeEndRun
(14:24:28)?


thanks
 
S

Sarath

Hi,

I am sorry that i didnt understand ur problem.
It is quiet obvious that time is an incrementing quantity.
So the start time will be less than the end time.

More over the difftime() takes two arguments time1,time0

i.e., difftime(time1,time0)

The difftime() function computes the difference between two calendar
times. difftime() returns the difference (time1-time0)
where..
time1 Is the ending time.
time0 Is the beginning time.
But u r passing starttime,endtime . I think this is where u are wrong.

If this is not the answer for ur question please be more clear with ur
question.

Sarath.B
IIIT-H
INDIA.
 
D

Dave Thompson

Code:
parseDate(&prod->tmbEndRun, date_rtu);
parseTime(&prod->tmbEndRun, prod->htime_rtu_fin);
printf("end %s\n", prod->htime_rtu_fin);

return me

05/06/10
end 14:24:28


Code:
parseDate(&prod->tmbStartRun, date_rtu);
parseTime(&prod->tmbStartRun, hactual_time);

return me

05/06/10
start 14:31:03

now i would like to have duration between us....

Code:
prod->timeEndRun=mktime(&prod->tmbEndRun);
prod->timeStartRun=mktime(&prod->tmbStartRun);
prod->stopRun = difftime(prod->timeStartRun, prod->timeEndRun);

printf("stop run: %d %ld %ld\n",prod->stopRun, prod->timeStartRun,
prod->timeEndRun);

that return me
stop run: -3205 1118428263 1118431468
Assuming the usual Unix time_t (seconds since 1970-01-01) those
numbers don't agree with the strings above unless there is a (zone
with) DST transition or other cut in the middle of a June afternoon
which is pretty unlikely. Assuming US Eastern time, hence EDT for all
of 05-06-10, they are 14:31:03 and 15:24:28 (not 14:24:28).

why prod->timeStartRun (14:31:03) is smaller then prod->timeEndRun
(14:24:28)?
14:31:03 would be _greater than_ (or after) 14:24:28, but is _less
than_ (or before) 15:24:28 by almost an hour. And your difftime call
gives start - end, the negative of the interval, and apparently is as
then expected negative almost 1 hour.

- David.Thompson1 at worldnet.att.net
 
C

collinm

i will try to explain...

run 1: i take time (i don't use this time)

i stop time endrun

run 2: i take time startrun

i want to calculate the difference between endrun (run 1) and startrun
(run 2)

the first time i call the function, difftime is bad... i call it
another time and it's ok...

my variable is ok...
 
K

Keith Thompson

collinm said:
i will try to explain...

I'm afraid you'll have to try a bit harder.
run 1: i take time (i don't use this time)

i stop time endrun

I *think* you mean that you call the time() function. What do you do
with the result?
run 2: i take time startrun

i want to calculate the difference between endrun (run 1) and startrun
(run 2)

So you're running the same program two separate times, and you want to
compare the result of the time() function from two different
executions? You'll need to save the results somewhere. Keep in mind
that the standard's only guarantee about time_t (the type of the value
returned by the time() function) is that it's an arithmetic type
capable of representing times.
the first time i call the function, difftime is bad... i call it
another time and it's ok...

I'm afraid I have no idea what "difftime is bad" means, or what you
consider to be "ok".
my variable is ok...

Variable? What variable?

Post some actual code, preferably both brief and complete. Tell us
what you want it to do, and how its actual behavior differs from what
you want.

(Also, your posts will be easier to read if you use standard
capitalization.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top