I am a beginner at CakePHP and I have o problem. I have to validate 2 dates(date_start & date_end). Date_end must be at least 30 days later than date_start. I am little confused of how to write the function for date difference. I don't know what parameteres I have to add and how to find them from the variable $validate. I also added another validation for the dates which tells date_end must be later than date_start and it works. Here's is the code of validations:
public $validate = array(
'user_id' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
),
),
'name' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
),
),
'date_start' => array(
'rule' => 'date',
'message' => 'Enter a valid date'
),
'date_end' => array(
'date' => array(
'rule' => array('date'),
'message' => 'The date must be valid'),
'dates' => array(
'rule' => 'dates',
'message' => 'The end date must be later tha start date'),
),
);
public function dates(){
if($this->data['Lesson']['date_end'] > $this->data['Lesson']['date_start']){
return true;
}
else{
return false;
}
}
public function date_diff($date_start, $date_end){
}
Do you do you know the code I should write in function date_diff?
Thank you!