Click to See Complete Forum and Search --> : function to calculate if date range is Invalid


psdeveloper
08-08-2008, 12:14 PM
I have 2 date selector text boxes passing the values to my php page. I thought I could turn the vales into unix time stand and then disregard any positive or negative values. This works on most dates, but when I was testing it, It did not turn "02-19-2008 00:00:00" into a unix time stamp, so therefore it did not do the calculation need to tell if rage is valid. Here is what I had...


$startdate = strtotime($Psdate);
$enddate = strtotime($Pedate);
$datediff = $enddate - $startdate;
//test to see if these even are valid date
if (checkdate($smon,$sday,$syea) && checkdate($emon,$eday,$eyea))
{
if ($datediff >= 0)
{

echo "Range is Valid";
}
else
{

$checkdate = 0;
echo "Range is Invalid";
$err_array[] = "Incorrect Date Range";

}
}

NogDog
08-08-2008, 09:02 PM
Can your form be modified to supply the date in a Y2K-compliant format: "yyyy-mm-dd hh:ii:ss"? strtotime() will also recognize "mm/dd/yyyy hh:ii:ss" with slashes, though this may be locale dependent, whereas the Y2K format will always work.

\\.\
08-09-2008, 02:17 AM
Convert to milliseconds.

Then compare future date with past date and if past date is < future date then you should be OK.