I am doing attendance system by using php/mysql. Here I got the logical problem when calculate the night shift working hours and If the out time is none.
if(isset($_POST['date']))
{
$date = $_POST['date'];
}
else
{
$date = date('Y-m-d');
}
$select = mysql_query("select * from `timelog` where `date`='$date' ORDER BY `time`");
$i=1;
while($row = mysql_fetch_array($select))
{
if($i==1)
{
$fv=$row['time'];
$first_value=new DateTime($row['time']);
$k=0;
}
if($i==2)
{
$sv=$row['time'];
$second_value=new DateTime($row['time']);
$difference = $first_value->diff($second_value);
$total = $difference->format('%h hours %i minutes %s seconds');
?>
<tr><td><?php echo $row['name'];?></td>
<td><?php echo $row['cardno'];?></td>
<td><?php echo $row['date'];?></td>
<td><?php echo date("g:i:s a", strtotime("$fv"));?></td>
<td><?php echo date("g:i:s a", strtotime("$sv"));?></td>
<td><?php echo $total;?></td></tr>
<?php
$k=1;
}
$i++;
if($k==1)
{
$i=1;
}
}
In database table I have added id,name,date,time.