Currently i'm working with Doctrine 2 and MySQL. I encounter some problems when I work with datetime fields in mysql respectively DateTime in PHP. When in my database the date value is "0000-00-00", in PHP this value is converted to -0001-11-30. I'm note pleased about that, so I need to make a check for "0000-00-00" value of date. Does anybody have some idea on this to help? Thanks.
N.B. I'm thinking if it is right to make checking on "-0001-11-30" instead of "0000-00-00".
The DATE and TIMESTAMP functions do exactly what you are looking for. If you have a STRING column where its format is like TIMESTAMP , you can simply apply it. Then, DATE will extract just the date and it takes care of the NULL values.
If the type isn`t specified, Flexmonster automatically assigns a type for a certain field according to a first value. Empty string and null values can not be recognized as dates, as the result date formatting does not work.
zeroDateTimeBehavior=convertToNull. --- See MySQL Manual: --- Connector/J x.x throws an exception by default when these values are encountered as this is the most correct behavior according to the JDBC and SQL standards.
DATETIME[( fsp )] A date and time combination. The supported range is '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999' . MySQL displays DATETIME values in ' YYYY-MM-DD hh:mm:ss [. fraction ]' format, but permits assignment of values to DATETIME columns using either strings or numbers.
If the date is not set use NULL
to indicate that state. That solves your problem and makes database schema much more clear and verbose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With