PHP Validation of form element

I'm struggling with this validation and hoping someone can help me improve my php. The form is a booking form and the field is a date element. The rule is, a booking date can be for the next day if made prior to 9am today, otherwise the minimum date is the day after tomorrow. There is obviously an issue in my code though as every date entered is accepted. My code is as follows:
PHP:
$app = JFactory::getApplication();
$data = JFactory::getDate($data)->toUnix();
//date entered
$day=date('D',strtotime($data));
//today
$date = new DateTime($string);

if (date('H',strtotime($date)) < 9) {
   $minDate = date('D',strtotime($date).' + 1 day' );
  }
else {$minDate = date('D',  strtotime($date).' + 2 days' );
}
if( $minDate <= $day){return true;}
else{return false;}
 
This should do:
Code:
$booking_date = date("Y-m-d", strtotime($data));
$hour_now = date("G");

if($hour_now < 9) {
  $min_date = date("Y-m-d", strtotime("+ 1 day"));
} else {
  $min_date = date("Y-m-d", strtotime("+ 2 day"));
}

return $booking_date >= $min_date;

You can always do a var_dump($variable_name);exit; in your code to see the actual values. E.g. date('D',strtotime($data)); gives you "Thu" and not numeric value. And then below you compare it to another day like if Thu > Fri, so you obviously get unexpected results.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top