PHP Comparison class files: yiisoft\yii2\validators\comparevalidator.php
JS Comparison class file: Yiisoft\yii2\assets\yii.validation.js
The original comparison contains only integer and string two cases
Increase the time comparison by adding types
The front desk is JS time Select plugin time format for Yyyy-hh-dd Hh:ii:ss and the like
PHP is converted to timestamp comparison time Strtotime ()
JS is using the new date () comparison time (be sure to new otherwise may be a problem)
if (Options.type = = = ' Number ') { = parsefloat (value ); = parsefloat (comparevalue);} Else if (Options.type = = = ' Strtotime ') { // Here is the newly added new Date (value); New Date (CompareValue);}
if($type= = = ' Number ') { $value= (float)$value; $compareValue= (float)$compareValue;}ElseIf($type= = = ' Strtotime ') {//here is the newly added $value=Strtotime($value); $compareValue=Strtotime($compareValue);} Else { $value= (string)$value; $compareValue= (string)$compareValue;}
After updating the JS file, be sure to delete the cache!
YII2 rules Add time comparison function