Page 1 of 1

time calculations

Posted: Tue Jan 11, 2005 2:37 am
by Czar
Hello

What is the best way to do this?

I have an employee database, which stores working hours of each employee. I insert the time when employee comes to work and when he/she leaves. Values in MySQL are for example in monday: field 'monday_1'= 08:14 and 'monday_2'= 16:44.

I want to get daily working hours of an employee, like "7.6" hrs etc... as a decimal number. I need this to build weekly and monthly working hour reports.

Thanks for any help.

Posted: Tue Jan 11, 2005 2:50 am
by Czar
...does MySQL's TIMEDIFF do the job?

Posted: Tue Jan 11, 2005 8:52 am
by feyd
TIMEDIFF is probably not the best route, if you want decimal forms..

Using some math, you can use UNIX_TIMESTAMP against the time values..

Code: Select all

SELECT ((UNIX_TIMESTAMP( monday_2 ) - UNIX_TIMESTAMP( monday_1 )) / 3600) AS hrs FROM your_table