Version: 1.0
Type: Function
Category: Calendars/Dates
License: GNU General Public License
Description: Check dates interval from two edit boxes inputed in form dd-mm-yyyy (instead of - sperator u can use . or /)
function okdata($date1,$date2)
{
// split date into day,month,year vars with separators / or . or -. U can add more seps
$splited1=split ('[/.-]', $date1);
$splited2=split ('[/.-]', $date2);
$day1=$splited1[0];
$month1=$splited1[1];
$year1=$splited1[2];
$day2=$splited2[0];
$month2=$splited2[1];
$year2=$splited2[2];
//extract last day from given month
$daymonth1=mktime(0,0,0,$month1+1,0,$year1);
$daymonth2=mktime(0,0,0,$month2+1,0,$year2);
$lastday1=strftime("%d",$daymonth1);
$lastday2=strftime("%d",$daymonth2);
//validate last day from given month
if ($day1>$lastday1)
{
$error=-1;
$outerr.="Invalid day of month for first field!";
}
if ($day2>$lastday2)
{
$error=-1;
$outerr.="Invalid day of month for second field!";
}
$mktime1=mktime (0,0,0,$month1,$day1,$year1);
$mktime2=mktime (0,0,0,$month2,$day2,$year2);
//calculate difference between dates
$diff=$mktime1-$mktime2;
if ($diff<0)
{
$error=-1;
$outerr.="First date cannot be greater than second date!<br>";
}
if ($diff==0)
{
$error=-1;
$outerr.="Second date cannot be equal with first date!<br>";
}
if ($error==-1)
{
return $outerr;
}
else
{
return "Date interval succesfully validated!";
}
}