Link to home
Start Free TrialLog in
Avatar of phper
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.
ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

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
You could also transform the datetime columns to a unix timestamp, and subtract:
SELECT
TimeOut,
TimeIn,
unix_timestamp(TimeOut)-
unix_timestamp(TimeIn) as TT
FROM
project_time

Open in new window

Avatar of phper
phper

ASKER

It's
TIMEDIFF(TimeOut,TimeIn) as TT

But you got it, thanks