0

I have used a php code to validate two dates.If date 1 = date 2 then return false els true.Below is the code where error is it is always returning false.

{
$d1 =$values['DATE'];     //date 1 in dd-mm-yyyy format
$d2 =$values['DATE_OF_LEAVE'];   //date 2 in dd-mm-yyyy format

if(strtotime($d1) != strtotime($d2)) 
{
    return true;  
}

echo '<script type="text/javascript">';
echo 'alert("Application date and leave date should be different.")';
echo '</script>';

return false; 
}
John Cartwright
  • 5,101
  • 21
  • 25
  • After return true put exit(); or put rest part in else part. but again you have to put exit(). Or may be the problem that date are same. – Anant Kumar Singh May 08 '15 at 18:32
  • i have two text boxes to accept dates.Where i put dates like 08-05-2015 and 08-05-2015 returns false.but when i put 08-05-2015 and 09-05-2015 returns false which should be true. – Saibal Chakravarty May 08 '15 at 18:40

1 Answers1

0

Set both to a least common denominator with date().

if(date('Ymd',strtotime($d1)) != date('Ymd',strtotime($d2))) 
Misunderstood
  • 4,529
  • 1
  • 14
  • 21