savagenoob Posted May 30, 2009 Share Posted May 30, 2009 I have a function on my site that allows users to clock in and clock out. I then have a report function that prints out like a timecard for them. I have an issue though, I need a way to manually enter a timestamp in case the employee misses a punch. The way I have been calculating time work is on every clock "Out" I would calculate the number of minutes since last clock "In" and put that total number of minutes in the database. Then on the report I just totalled the minutes in that row between the 2 dates the user selects. But I can't do this when you enter a manual timestamp, and I can't think of how to accomplish this task. Was wondering if someone had any suggestions. Link to comment https://forums.phpfreaks.com/topic/160309-timeclock-script-help/ Share on other sites More sharing options...
thebadbad Posted May 30, 2009 Share Posted May 30, 2009 You can't calculate the minutes between two 'stamps? Here's how: If the stamps from the database are Unix timestamps: <?php //clock in timestamp from database $in = '1243699999'; //manually entered date and time $out = '2009-05-30 20:00:00'; //calculate difference in minutes $diff_mins = (strtotime($out) - $in) / 60; ?> If $in is a date-time stamp, just add an additional strtotime(): $diff_mins = (strtotime($out) - strtotime($in)) / 60; Link to comment https://forums.phpfreaks.com/topic/160309-timeclock-script-help/#findComment-845979 Share on other sites More sharing options...
savagenoob Posted June 1, 2009 Author Share Posted June 1, 2009 Thats how I want to do it, I just want to store the times as unix timestamps, but there will be a list of timestamps like... ID Employee Timestamp In/Out 1 Jerry 12345678 In 1 Jerry 12345679 Out 1 Jerry 12345680 In 1 Jerry 12345681 Out and I need to figure out how to calculate just from the In's to the Out's, so this example would output 2 timeframes and then I would add the 2 timeframes together... just dont know how to loop through it logically.... Link to comment https://forums.phpfreaks.com/topic/160309-timeclock-script-help/#findComment-846491 Share on other sites More sharing options...
savagenoob Posted June 3, 2009 Author Share Posted June 3, 2009 Any guru with a suggestion? I cant figure it out. Need to figure out a way to calculate between each in to out within a time frame specified. Only problem that there might be an unlimited amount of sets of ins and outs to calculate and I dont know how to write this. Link to comment https://forums.phpfreaks.com/topic/160309-timeclock-script-help/#findComment-848891 Share on other sites More sharing options...
thebadbad Posted June 4, 2009 Share Posted June 4, 2009 You're storing the data in a database, right? Show me how you retrieve the data, and I'll try to help you with the calculations. Link to comment https://forums.phpfreaks.com/topic/160309-timeclock-script-help/#findComment-849096 Share on other sites More sharing options...
savagenoob Posted June 5, 2009 Author Share Posted June 5, 2009 OK, well, this is the old way I did it with pre-calculated minutes... <?php if($_POST['report'] == "time") { ?> <table border="1"> <tr><th>Date/Time</th><th>Punched</th></tr> <?php $date1 = mysql_escape_string($_POST['Date1']); $date2 = mysql_escape_string($_POST['Date2']); $date1 = strtotime($date1); $date2 = strtotime($date2); $newdate1= date('Y-m-d', $date1); $newdate2= date('Y-m-d', $date2); $time2 = " 00:00:01"; $time = " 23:59:59"; $date3 = $newdate2 . $time; $date4 = $newdate1 . $time2; $employee = $_SESSION['SESS_MEMBER_ID']; $query="SELECT Clock, Time FROM timeclock WHERE Employee = '$employee' AND Time BETWEEN '$date4' AND '$date3'"; $result = mysql_query($query); while($myrow = mysql_fetch_assoc($result)) { $convertime = strtotime($myrow['Time']); $convertime = date("l, m/d/Y, g:i a ", $convertime) ?> <tr><td><?php echo $convertime; ?></td><td><?php echo $myrow['Clock']; ?></td></tr> <?php } $fquery="SELECT SUM(MinutesClock) AS MinutesClock FROM timeclock WHERE Employee = '$employee' AND Clock = 'Out' AND Time BETWEEN '$date4' AND '$date3' "; $fresult = mysql_query($fquery); while($myfrow = mysql_fetch_assoc($fresult)) { $min2hours=$myfrow['MinutesClock']; $printhours = m2h($min2hours); $finalhours = explode('.', $printhours); ?> <tr><th>Total Time Worked: <?php echo $finalhours[0];?> Hours <?php echo $finalhours[1];?> Minutes</th></tr> </table> <a class="button" target="_blank" href="fpdftest.php?ID=<?php echo $employee;?>&Date=<?php echo $date4;?>&Date2=<?php echo $date3;?>" onClick="this.blur();"><span>Export to PDF</span></a><br /><br /><br /> <?php } ?> Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/160309-timeclock-script-help/#findComment-849702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.