Page 1 of 1

Time Difference

Posted: January 16th, 2019, 1:38 am
by Socio
Dear all

I would like to calculate time difference of STARTING & END of interview.
I'm using auto calculation of time from system.

Starting time
preproc
START=int(systime()/1);

End time
preproc
END=int(systime()/1);


Interview time taken ??

Thank you.

Re: Time Difference

Posted: January 16th, 2019, 6:53 am
by Gregory Martin
You are better off using the timestamp function for things like this. It returns the number of seconds since 1970, which means that subtracting the end timestamp from the beginning timestamp gives you the total time (in seconds).

Using systime is tricky because you would have to convert the time into a value that can be used in a subtraction operation. I think there are examples on the forum of doing this, but I would stick with timestamp.

Re: Time Difference

Posted: January 16th, 2019, 7:31 am
by Socio
Hi Gregory Martin

Thank you for your timely reply.
I can't find much about timestamp or couldn't understand much. What should be the length in the dict.

If possible can you elaborate with an example.
Sorry for the inconvenience. Thank you.

Re: Time Difference

Posted: January 17th, 2019, 12:34 pm
by josh
Look at the example in the help for timestamp: http://www.csprousers.org/help/CSPro/ti ... ction.html

Put that logic in the preproc of the questionnaire. SURVEY_DURATION will be the time in seconds.

Re: Time Difference

Posted: January 18th, 2019, 12:38 pm
by Socio
Hi Josh and Gregory Martin

I'm very sorry and my apologies beforehand.
I have tried the timestamp(), however couldn't get the result.

I'm attaching the file where you can checked and clear my doubts.

Thank you and sorry for the inconvenience.
TIME TESTING.rar
(58.44 KiB) Downloaded 256 times

Re: Time Difference

Posted: January 18th, 2019, 1:13 pm
by khurshid.arshad
Please use this code

Code: Select all

PROC START

Preproc
$=timestamp();


PROC END_TIME
preproc
END_TIME =timestamp();

PROC DURATION
Preproc
    DURATION = End_time-Start;
Best.
a.

Re: Time Difference

Posted: January 18th, 2019, 3:39 pm
by josh
The timestamp() function gives you the time at the moment that you call it so you want to call it once to get the start time at the beginning of the form and then call it again at the very end of the form. That will give the start and end times. Then you can subtract the start from the end to get the duration.

So you need to put the variable START at the beginning of the questionnaire and set START=timestamp() in the proc for START. Then set END_TIME=timestamp() in the END_TIME PROC at the end of the form. Finally calculate the duration at the end of the questionnaire by setting it equal to END minus START.

Currently you are setting START to timestamp() inside the proc for DURATION and then getting the end time and calculating the difference all the in DURATION proc. This is always going to be too small since you are going to get the time spent inside that field.

Re: Time Difference

Posted: January 20th, 2019, 4:05 am
by Socio
Hi Josh and khurshid.arshad

Thank you for your timely reply.
I have written the same however it is showing ******* in the variables.
I have given 6 length (numeric) in start and end time. And 5 length (numeric) in duration time.

Am I doing something wrong.

Thanks.

Re: Time Difference

Posted: January 20th, 2019, 7:26 am
by khurshid.arshad
variable length not matched with timestamp. Please increase variable length till 10.

Best.
a.

Re: Time Difference

Posted: January 21st, 2019, 6:55 am
by Socio
Thank you Josh and Khurshihd