I am using a system that tells me how many days out of 7 days it has taken for a user to re-submit data in a form to the database. The below script measures how many days have past from the original start date / when the form was originally filled out to when it was completed.
Basically, I am trying to echo 2 different measures, if the days that have past from the start date are less than 7, then it should echo out (number of days) out of 7 past
i.e. 1 day of 7 past or 4 days of 7 past
and if it has gone over 7days, it should then say (number of days) overdue
.
The problem I am getting is that I am allowing my users 7 days to submit the form. Bearing this in mind, they are not overdue therefore until it has gone past the 7 days timeframe, therefore if a user takes 8 days to complete the form they should only be one day overdue, however my script currently says 8 days overdue, as it takes into consideration the earlier 7.
Is there a way I can minus 7 days to show once a user goes over the 7 day time frame?
<?php include 'config.php';
$data = mysql_query("SELECT *, TIMESTAMPDIFF(DAY, date, CURDATE()) AS expire_date FROM supplier_session ORDER BY expire_date ASC")
or die(mysql_error());
echo "<table class=\"table\" style=\"width:995px; font-family: 'Lucida Grande', Tahoma, Verdana, Arial, sans-serif;
font-size:11px;\" >
<tr>
<td style=\"width:100px;\">ID:</td><td>Company Name:</td><td>Company Reg No:</td><td>Application Started:</td><td style=\"width:200px;\">Application Duration:</td><td style=\"width:100px;\">Date:</td><td>Status:</td></tr>";
while($row = mysql_fetch_array( $data )) {
$days = $row['expire_date'];
$when = $days*0;
$str = $row['expire_date'];
$str2 = substr($str, 0); // "quick brown fox jumps over the lazy dog."
if ($when <= 31){
echo "<tr><td style=\"width:100px;\"><p>".$row['id'] . "</p></td>";
echo "<td style=\"width:150px;\"><p>".$row['company_name'] . "</p></td>";
echo "<td style=\"width:150px;\"><p>".$row['company_reg_number'] . "</p></td>";
echo "<td>"; echo date('d/m/Y',strtotime($row['date'])); echo "</td>";
if ($days >= 8) {
echo "<td style=\"width:200px;\"><p>{$str2} days overdue</td>";
}
elseif ($when <= 7){
echo "<td style=\"width:200px;\"><p>{$str2} of 7 days past</td>";
}
}
echo "<tr>";
}
echo "</table>"; //Close the table in HTML
?>
The date_sub() function subtracts some days, months, years, hours, minutes, and seconds from a date.
If you want 7 days back from today you can use this:
date('Y-m-d', strtotime('-7 days'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With