[BUG] Form dateField and default value in MSSQL

When using dateField method with MSSQL database it produce next HTML:


<input name="Cost[DateOrder]" id="Cost_DateOrder" type="date" value="1995-09-01 00:00:00.000">

This last time part in value attribute prevent browser to correctly display default value. Chrome displays nothing. I know that in MySQL we can use DATE field, but MSSQL doesn’t have it, it always provides data with time part.

Any ideas? This is unexpected behavior of yii(bug), in MySQL all is working. In MSSQL dateField implemented in 1.1.11 not working at all.

I believe that this is not Yii bug. It is just one more illogical behavior of MSSQL.

I also working with PHP/MSSQL for a plenty of time. So, I got used to implement different workarounds.

Fortunately, Yii and PHP in general are flexible enough to do this.

Different workarounds for simple dateFields is not a good idea, I believe.

Yes, you are right.

However, the described problem comes from the MS SQL database engine. For me, it is not normal then you are using type ‘date’ and the database engine returns to you ‘datetime’ value.

There are three ways how to solve this problem:

  1. Implement a workaround in your own code,

  2. Beg developers to implement workaround in the Yii code,

  3. Beg Microsoft to do something with this :).

There are pros and cons of both ways.

But, definitely, this is not a Yii bug.

Best wishes.

One little moment (which cause the problem) - MSSQL doesn’t have DATE field type! I don’t mind, you can name it on your own, but $form->dateField don’t working with MSSQL.