Can any one tell me how to add validation to date along with the time
There is some format like "yyyy-MM-dd" for date as in
public function rules()
{
return array(
array(‘myDate’, ‘type’, ‘type’ => ‘date’, ‘message’ => ‘{attribute}: is not a date!’, ‘dateFormat’ => ‘yyyy-MM-dd’),
);
}
But wat format shud we follow to add time in this eg. i want to have format as 2010-01-01 12:38:30 now hw to validate it.
Y11
(Y!!)
January 8, 2010, 12:00pm
2
There is another type you can use called datetime . See here .
So something like this should work:
public function rules()
{
return array(
array('myDate', 'type', 'type' => 'datetime', 'datetimeFormat' => 'yyyy-MM-dd hh:mm', 'message' => '{attribute}: is not a date!'),
);
}
Hi,
Thanks for the reply and its working too but I need the validation uptill seconds format
I mean the format should include seconds also and no such format is mentioned in the class reference document
Y11
(Y!!)
January 8, 2010, 1:06pm
4
Ok, I think this pattern should work:
yyyy-MM-dd hh:mm:ss
See here it says:
And at CDateTimeParser you find the possible pattern characters.
I tried something similar but it was not working…but this one is working absolutely fine…
Thanks a lot for help.