Time Difference

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
Socio
Posts: 48
Joined: May 1st, 2017, 4:47 am

Time Difference

Post 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.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Time Difference

Post 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.
Socio
Posts: 48
Joined: May 1st, 2017, 4:47 am

Re: Time Difference

Post 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.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Time Difference

Post 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.
Socio
Posts: 48
Joined: May 1st, 2017, 4:47 am

Re: Time Difference

Post 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 249 times
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Time Difference

Post 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.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Time Difference

Post 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.
Socio
Posts: 48
Joined: May 1st, 2017, 4:47 am

Re: Time Difference

Post 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.
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Time Difference

Post by khurshid.arshad »

variable length not matched with timestamp. Please increase variable length till 10.

Best.
a.
Socio
Posts: 48
Joined: May 1st, 2017, 4:47 am

Re: Time Difference

Post by Socio »

Thank you Josh and Khurshihd
Post Reply