Jump to content

TimeSheet Application


JustinK101

Recommended Posts

I am devolping a timesheet application, and I need to figure out how to subtract times and get total hours in a single day.

I will have the following variables in a mysql table for each day, i.e. each row stores the following datetime mysql variables:

[b]Acutally now I am thinking about it, should each of these clockIn and clockOut mysql entries simply be a time data type instead of datetime? Since, each record is a single day, in theory I shouldnt need the date. Thanks for advice on this as well.[/b]

EXAMPLE:

[code]
clockIn1 = 2006-06-15 09:00:51
clockOut1 = 2006-06-15 12:00:12

clockIn2 = 2006-06-15 13:00:18
clockOut2 = 2006-06-15 15:30:44

clockIn3 = 2006-06-15 15:45:23
clockOut3 = 2006-06-15 17:00:14

clockIn4 = 0000-00-00 00:00:00
clockOut4 = 0000-00-00 00:00:00

clockIn5 = 0000-00-00 00:00:00
clockOut5 = 0000-00-00 00:00:00
[/code]

NOTE: clockIn and clockOut 4 and 5 were not used in this example but they could have been. Also the opposite is true, there may be a case where ONLY clockIn1 and clockOut1 are filled, the other 4 pairs of variables could be zeroed out.

[b]How do I calulate the total amount of time in this example work day in hours:minutes:seconds from this data? Thanks guys![/b]
Link to comment
Share on other sites

Convert the time into the number of seconds since 1-1-1970 by using strtotime() or one of the other date/time functions. Subtract. Take the result and divide by 3600 (the number of seconds in an hour).

There have been quite a few posts on how to return the number of hours, minutes and seconds in the last few weeks. They shouldn't be hard to find.

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.