JustinK101 Posted June 16, 2006 Share Posted June 16, 2006 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:51clockOut1 = 2006-06-15 12:00:12clockIn2 = 2006-06-15 13:00:18clockOut2 = 2006-06-15 15:30:44clockIn3 = 2006-06-15 15:45:23clockOut3 = 2006-06-15 17:00:14clockIn4 = 0000-00-00 00:00:00clockOut4 = 0000-00-00 00:00:00clockIn5 = 0000-00-00 00:00:00clockOut5 = 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] Quote Link to comment https://forums.phpfreaks.com/topic/12124-timesheet-application/ Share on other sites More sharing options...
kenrbnsn Posted June 16, 2006 Share Posted June 16, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/12124-timesheet-application/#findComment-46170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.