Active Record date validator not working in Windows

I have a really strange problem. I have model attribute rules that specify a date format for ‘start_at’ and ‘end_at’ in one of my models. It looks like this…

    public function rules()


        return [

            [['name'], 'required'],

            [['course_id', 'rental_id'], 'integer'],

            [['name'], 'string', 'max' => 255],

            [['description'], 'string', 'max' => 1455],

            [['start_at', 'end_at'],'date','format' => 'yyyy-mm-dd H:i:s'],

            [['is_internal'], 'boolean'],




In a Unix environment it works perfectly fine given a date of ‘2016-06-11 16:30:00’. However, in a windows environment I get an error saying “The format of Start At is invalid” and “The format of End At is invalid”. I checked the date string in both Linux and Windows and they are exactly the same.

Why would this validator work differently in a Linux host as opposed to Windows host and how do I fix it?

Check the notes on this one:$format-detail

Looks like you can fix it either like this:

[['start_at', 'end_at'],'date','format' => 'php:yyyy-mm-dd H:i:s'],

or like this:

[['start_at', 'end_at'],'date','format' => 'yyyy-mm-dd H:m:s'],

Thanks for the suggestion Patrick but neither of these worked. I still get validation error. It works perfectly fine in my LAMP stack but not in my WAMP stack.

And when you say

you mean that you checked the properties of the model?

Yes, using xdebug I set a break-point and checked the values. It was in this format, “2016-06-11 16:30:00”. For some reason the validator didn’t like that in my Windows environment. I had to remove the date validation to get it to work on my WAMP stack. Again, in my Linux environment it worked fine.

This seems like a bug in the Yii2 framework. Can we get this fixed please?

Please report a bug here: