In Yii I am writing a small application called Invoice Application. In that I have two fields called Invoice Issue Date and Due Date. I want validation for both of the input date fields so that Due Date must be greater than Invoice Issue Date. So I made the following rule in the model:
public function rules (){
array('due_date','compare','compareAttribute'=>'invoice_issue_date',
'operator'=>'>',
'allowEmpty'=>false,'message'=>'Due Date must be greater then Invoice Issue Date.'),
}
It is working fine but when in one field there is a two digit date (10 to 31) and another has a single digit date (1 to 9) then this validation not working at all. Can someone tell me what is wrong here? Any help and suggestions are welcome.
UPDATE
For dates I am using CJuiDatePicker to enter date fields.
I think, this is a common mistake many PHP developers do.
correct way is …
you may want to write your own validation method or convert those dates to integers before validation.
EDIT
add this to your model class