time calculations

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

time calculations

Post 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.
Czar
Forum Commoner
Posts: 58
Joined: Sun Dec 29, 2002 11:17 am

Post by Czar »

...does MySQL's TIMEDIFF do the job?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
Post Reply