When user logs in, the timestamp get sent to database and stored in column "in" with datatype TIME, when user logs out, execute query :
Update TABLE Set out=current_time, tot=(current_time-in) WHERE id=01
where "in","out" and "tot" are columns of your table
column "tot" will store data in format " 00:48:02 ".
NOTE all coulmns "in", "out", "tot" has datatype TIME