So I've been creating this timecard system to track punch in/out for employees and everything has been going along just fine but there are some things that I want to speed up but I'm not sure if it can be done. I have one table called punchlog, each time someone punches in or out this table gets a new row. I have the following fields: -punchid -employeeid -systemtime -systemdate -punchtime -punchdate -inout The "inout" field is the only one that isn't really needed. Anyways, I want two queries, one to get the total time punched IN for a day and one to get the total time punched in for a given week. I've been using the mysql functions TIMEDIFF to get the hours worked and I've been using DAYOFWEEK for calculating all the days in a week. I just can't figure out how to compare the values from two different rows let alone do it several times for a single day (punch outs for breaks, lunch, etc). In PHP I just calculate the last day of the week for any given date then step back 6 days and on each day I run a few loops to get the daily hours, etc. Is there any way to port this more to mySQL or am I hindered because I need so many ifs and loops?