I use PHP, jQuery AJAX and HTML to create a schedule system, for this the user needs to select 2 dates within 1 month from each other. The system is still working and shows (very limited) data.
BUT! When I actually choose a date for the month limit (i.e. 2 months further than at the beginning or another year after the start), it still shows a table with the data.
For this, I have this check:
$dt1 = new DateTime($_REQUEST['startdate']);
$dt2 = new DateTime($_REQUEST['enddate']);
$diff = date_diff($dt1, $dt2);
if($diff->m > 1 || $diff->y > 1)
{
print("<center><strong>Time between dates it too great<br />Please choose another date or time within a month of each other</strong></center>");
die();
}
Dates are passed by the jQuery dating object via AJAX, and the dates that I use, for example, are passed as such:
11/14/2015 ( ) && & 12/14/2015 ( ) -
14.09.2015 ( ) && 12/14/2015 ( ) - , 11/14/2015 ( ) && 12/14/2016 ( ) - ,
, , , , , , , :
function CountDaysBetween($startDate, $endDate)
{
$begin = strtotime($startDate);
$end = strtotime($endDate);
if ($begin > $end) {
echo "start date is in the future! <br />";
return;
} else {
$no_days = 0;
$weekends = 0;
while ($begin <= $end) {
$no_days++;
$what_day = date("N", $begin);
if ($what_day > 5) {
$weekends++;
};
$begin += 86400;
};
$working_days = $no_days - $weekends;
return $working_days + 1;
}
}
Edit
2 , , ,