Jump to content

Timeclock Script Help


savagenoob

Recommended Posts

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

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;

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....

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.