Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8913321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:25:51+00:00 2026-06-15T04:25:51+00:00

Edit: Thanks to barnyr I have the average in seconds, so now I just

  • 0

Edit: Thanks to barnyr I have the average in seconds, so now I just need to convert it to the correct format. Unfortunately the Coldfusion functions noted by Peter only take a datetime object, so I’m back to being stumped by the conversion.

I have a two-fold question. I need to generate the average time it took Y users to complete a task, and then display the result in a specific format: x Years x Months x Weeks x Days x Hours x Minutes x Seconds.

My backend database is SQL Server 2008, and I’m running the queries through Coldfusion 10. Both columns are datetime fields.

The query is (similar to):

SELECT    Started_Date, Completed_Date
FROM      tbl_progress
WHERE     0=0

I then need to iterate through the query results, get the difference between the Completed_Date and Started_Date (ie. duration), average the results, and display as noted above.

From another thread on Stackoverflow I got the following code, but it will only work for the days/hours/minutes/seconds sections of the required format.

<cfloop query="complete_time">
    <cfset completed = ParseDateTime(complete_time.Completed_Date) />
    <cfset started = ParseDateTime(complete_time.Started_Date) />
    <cfset difference = (completed - started) /> 
    <cfset fixed_diff = Fix(difference) />  
    <cfset days = fixed_diff /> 
    <cfset hours = TimeFormat(difference, "H") /> 
    <cfset minutes = TimeFormat(difference, "m") />  
    <cfset seconds = TimeFormat(difference, "s")/ >
</cfloop>

I need to know how/where to do the averaging, and how to get the years/months/weeks values for my required format. Date math is definitely not my best subject! Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:25:52+00:00Added an answer on June 15, 2026 at 4:25 am

    I would do the work in the database if you possibly can:

    SELECT    Started_Date, 
              Completed_Date, 
              DATEDIFF(Second, Started_Date, Completed_Date) AS sec_diff
    FROM      tbl_progress
    

    You can then compute the seconds into minutes, hours etc in ColdFusion.

    As you work through the results, you could sum up the sec_diff values. Then divide them by the number of row in your result set.

    You could also average the results in a query. Tave a look at SQL’s AVG() function.

    I’m not near a SQL server, but you may be able to use the following:

    SELECT    Started_Date, 
              Completed_Date, 
              DATEDIFF(Second, Started_Date, Completed_Date) AS sec_diff,
              AVG(DATEDIFF(Second, Started_Date, Completed_Date)) AS average_task_time
    FROM      tbl_progress
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please let me know if you have any idea about it. Thanks EDIT What
EDIT: I have fixed all but two warnings now, so thank you all for
Edit: Thanks- I understand it a lot more now. Its very confusing when you
Edit: Thanks folks, now I see my mistake. If I'm not wrong, because of
Edit: Thanks @BlackFrog. I think I'm nearer now, but the values are still not
EDIT: thanks for all the speedy responses, I have a much better understanding of
When don't you need to use runat=server in ASP.NET? EDIT: Thanks for all the
EDIT Thanks to all for your input. I guess my question was just a
EDIT: Thanks all of you. Python solution worked lightning-fast :) I have a file
Why new()/delete() is slower than malloc()/free()? EDIT: Thanks for the answers so far. Please

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.