如何验证Yii中的开始日期是否应大于当前日期

jexiocij  于 2022-11-09  发布在  其他
关注(0)|答案(2)|浏览(193)

我有一个表单中的一个开始日期字段在那里。我需要检查输入的开始日期是否大于当前日期使用yii验证规则。
有人能帮我做这件事吗?

g9icjywg

g9icjywg1#

这可能有效(需要添加到模型规则中)

array('startDate', 'compare', 'compareValue' => date("Y-m-d"), 'operator' => '>'),
u4dcyp6a

u4dcyp6a2#

$date_today          = date('Y-m-d', strtotime(' -1 day')); 
                           // -1, -2 depend on how back you want to go!!
  $date_today          = date("m/d/Y", strtotime($date_today));

   return [   
        [
          'alert_start_date', 'compare', 'compareValue' => $date_today, 
                                                 'operator' => '>',   
          'message' => $attribute.'Alert Start Date Cannot be a date in the past'
        ], 
    ];

相关问题