Jump to content


Photo

TimeSheet Application


  • Please log in to reply
1 reply to this topic

#1 JustinK101

JustinK101
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego, California, US

Posted 16 June 2006 - 04:12 AM

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:

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.

EXAMPLE:

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

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.

How do I calulate the total amount of time in this example work day in hours:minutes:seconds from this data? Thanks guys!

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 June 2006 - 04:55 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users