Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue handling dates in doctrine php

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

like image 997
robasc Avatar asked Feb 18 '26 06:02

robasc


2 Answers

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

like image 55
Maxence Avatar answered Feb 20 '26 21:02

Maxence


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.

like image 41
robasc Avatar answered Feb 20 '26 19:02

robasc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!