Reputation: 118
I have a ISO8601 datetime value in the following format (generated by JS):
var d = new Date(),
dateString = d.toISOString(); // returns "2017-08-17T07:39:34.502Z"
In my model, I want to create a validation rule to validate this value.
I have tried the following format, but it is reporting that the datetime string is invalid:
public function rules()
{
return [
...
['endTime', 'datetime', 'format' => 'php:DateTime::ATOM'],
...
];
}
I used DateTime::ATOM
instead of DateTime::ISO8601
because that's what the PHP documentation itself recommends.
Any ideas how to make this work?
Upvotes: 3
Views: 1135
Reputation: 18021
['endTime', 'date', 'format' => 'php:' . \DateTime::ATOM],
Edit: datetime
was wrong - proper validator is date
Upvotes: 5