tags:

views:

55

answers:

4

Hey.

I have a table with a field called date_start and a field called date_end The values of the field are like this

year-month-day hours:minutes:seconds

I need to find out:

  • How much time it to for the person to complete the task.
  • The average time it took of all of them.

I'm still a bit new and honestly have no idea where to even start with this.

Thanks for all the help.

A: 

Start here: strtotime() This function will convert your times to a number representing the number of seconds since 1970. You can then subtract one from the other to find elapsed seconds.

http://us3.php.net/strtotime

Scott Saunders
what if an application goes into the next day saydate_start = 2009-01-13 18:53:28 date_end= 2009-01-14 14:39:10
Karl Lenz
srtotime("$date_start");strotime("$date_end");will that still give me the amount of seconds?
Karl Lenz
$num_seconds = strtotime($date_end) - strtotime($date_start);
Scott Saunders
A: 

I haven't tested it but this would work:

SELECT (UNIX_TIMESTAMP(date_end) - UNIX_TIMESTAMP(date_start)) AS personal_complete_time, 
AVG(UNIX_TIMESTAMP(date_end) - UNIX_TIMESTAMP(date_start)) AS total_average 
FROM mytable

You'll get average number of seconds to complete

Matt Williamson
A: 

You say you have a table with dates stored in this format:year-month-day hours:minutes:seconds.

Are you sure you're not using a datetime field? If so, that solves half your problem. Datetime fields are represented in this manner.

ajacian81