问题
I am having a issue with a date format issue. I am using mysql, doctrine2, and php 5.3.
The issue is when I query the database getRepository('Entity\\Srm').findBy($id)
I end up with a negative date value of: -0001-11-30 00:00:00
.
The value that is currently store in the database is 0000-00-00
. The datatype of the field in mysql is date
.
The doctrine entity has the variable identified as a date
type.
I have done tons of searching with and no good leads.
Any Ideas?
Thanks
回答1:
If you can alter the database, add the nullable attribute on your column and replace 0000-00-00 values with null.
Else, you need to implement a custom type: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/advanced-field-value-conversion-using-custom-mapping-types.html
回答2:
I found the solution to my problem. I had the annotations set to date on the attributes in the entities, so I decided to remove the annotations in order to PHP handle them. Now it's working since it is queried as a string type and not date type. I guess this is what I get coming from the static world vs. the dynamic world.
来源:https://stackoverflow.com/questions/10897380/issue-handling-dates-in-doctrine-php