我想比较有效日期应该小于生效日期。我的演示代码是..
public function addValidations()
{
parent::addValidations();
$this->validate['EffectiveToDate'] = array
(
'notempty' => array
(
'rule' => array('comparison', 'greater or equal', 'EffectiveFromDate'),
'allowEmpty' => false,
'message' => 'Effective From Date Greater Than To Date.',
),
);
}
所以,请建议我适当的解决方案。
答案 0 :(得分:2)
尝试此代码,看看它是否对您有所帮助。
public $validate = array(
'datecompare' => array(
'rule' => 'dateCompare',
'message' => 'Effective From Date Greater Than To Date.'
)
);
public function dateCompare($check) {
$datetocheck = strtotime('16/03/2014');
$today = strtotime(date('dd/mm/yyyy'));
if($datetocheck >= $today)
{
return true;
}
}
干杯!