Page 1 of 1

TIMEDIFF

Posted: Wed Nov 15, 2006 6:00 pm
by winsonlee
$sql = "SELECT in_date, in_time, out_date, out_time, TIMEDIFF(out_time,in_time) FROM XXX";

Just wondering for the TIMEDIFF funciton, I can only put in one column name for time in and out or I can put in the date as well ???

i tried something like TIMEDIFF(out_date.out_time,in_date.in_time)
it doesnt seems to be working

The following data is in my table
in_date in_time out_date out_time
10/11/06 00:02 10/11/06 00:02
10/11/06 00:02 10/11/06 00:03
15/11/06 15:41 16/11/06 09:34

Posted: Wed Nov 15, 2006 7:52 pm
by volka
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html wrote:TIMEDIFF() returns expr1 – expr2 expressed as a time value. expr1 and expr2 are time or date-and-time expressions, but both must be of the same type.
So don't use separate fields for date and time, use one single DATETIME field
in_date + in_time => login
out_date + out_time => logout