• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

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?

1 Solution
no its very good to let SQL do most of the processing, thats how I mostly do my stuff, I mostly use cf only to display..

If you need minutes you could ofcourse immediately convert the difference to minutes, unless you also need seconds?
Renante EnteraSenior PHP DeveloperCommented:
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
  Select Datediff(ss, startDateTime, endDateTime) as secDiff
  From Survey

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

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

Hope this helps.  Just try.

eNTRANCE2002 :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now