phper
asked on
get difference in time from 2 timestamps
I have 2 timestamp columns in a db table. One is TimeIn the other is TimeOut.
What I'm trying to do is find the total time, i.e. the difference between the 2 columns. What I thought would work is just subtract the 2 but I get a weird responses.
Here's my query:
SELECT
TimeOut,
TimeIn,
(TimeOut-TimeIn) as TT
FROM
project_time
But what I get is the following:
2/12/2009 10:37:40 | 2/12/2009 10:37:30 | 10
2/12/2009 10:39:21 | 2/12/2009 10:37:21 | 200
2/12/2009 10:40:00 | 2/12/2009 10:39:30 | 70
2/12/2009 10:53:00 | 2/12/2009 10:52:00 | 100
2/12/2009 11:06:28 | 2/12/2009 10:57:36 | 4892
2/12/2009 11:08:04 | 2/12/2009 11:06:49 | 155
What I want is the total Seconds. From there I can compute the Min & Hours. I've also tried both Timestamp and Datetime but both had the same results.
What I'm trying to do is find the total time, i.e. the difference between the 2 columns. What I thought would work is just subtract the 2 but I get a weird responses.
Here's my query:
SELECT
TimeOut,
TimeIn,
(TimeOut-TimeIn) as TT
FROM
project_time
But what I get is the following:
2/12/2009 10:37:40 | 2/12/2009 10:37:30 | 10
2/12/2009 10:39:21 | 2/12/2009 10:37:21 | 200
2/12/2009 10:40:00 | 2/12/2009 10:39:30 | 70
2/12/2009 10:53:00 | 2/12/2009 10:52:00 | 100
2/12/2009 11:06:28 | 2/12/2009 10:57:36 | 4892
2/12/2009 11:08:04 | 2/12/2009 11:06:49 | 155
What I want is the total Seconds. From there I can compute the Min & Hours. I've also tried both Timestamp and Datetime but both had the same results.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It's
TIMEDIFF(TimeOut,TimeIn) as TT
But you got it, thanks
TIMEDIFF(TimeOut,TimeIn) as TT
But you got it, thanks
Open in new window