Link to home
Start Free TrialLog in
Avatar of akawoody
akawoody

asked on

SQL or ColdFusion?: Determine length of time to take a survery

I am putting together a survey. I'm capturing the datetime when the person starts the survey (startDateTime) and the datetime they finish (endDateTime).

I want to be able to calculate the length of time each person took, as well as determine average time to complete.

I'm using the following code:

select Datediff(ss, startDateTime, endDateTime) as secDiff
from Survey

This will give the response in seconds which I can calulate into minutes:seconds.

Does this seem correct or is there another way that's better?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Tacobell777
Tacobell777

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Renante Entera
Yah! Tacobell777 is right.

It is adviceable to let SQL do the job.  Then I would suggest to use stored procedure.

So the process would be like this :

---------------------
On Your Database
---------------------
-- Create a Procedure
CREATE PROCEDURE GetTimeLength
As
Begin
  Select Datediff(ss, startDateTime, endDateTime) as secDiff
  From Survey
End

----------------------
On Your .cfm Page
----------------------
<!--- Call the Procedure using <cfstoredproc> tag --->
<cfstoredproc procedure="GetTimeLength" datasource="DSN">
  <cfprocresult name="GetRecord">
</cfstoredproc>

<!--- Display result of the procedure --->
<cfoutput query="GetRecord">
  #currentrow# - #secDiff#<br>
</cfoutput>

Hope this helps.  Just try.


Goodluck!
eNTRANCE2002 :-)