-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dummy mysql date ie. '0000-00-00' is presented as -0001-11-30 in Cycle in a View #509
Comments
What does |
The $datehelper->style() provides the format 'Y-m-d'. This is the format that I have chosen for my dates to be presented as. I could have chosen one of 13 formats. To elaborate: The user of the software can go into settings and select a date format of their choice whether it be d.m.Y or Y-m-d out of a possible 13. This dropdown is available under Settings...View within the software itself. |
I have managed to resolve the problem with the following code. Perhaps you can suggest something better. I am using the below code to present this date as a dummy date in the view or even as an empty string. |
I dont know why Cycle returns the '-0001-11-30'. Is this a substitute date in cycle as well? There is nothing in the documentation and nothing in their issues as well. |
What time inside |
Ok just var_dumped it and I get the following: object(DateTimeImmutable)#4227 (3) { ["date"]=> string(27) "-0001-11-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } |
I am going to leave this topic open. I am going to present the date as '0000-00-00' for the time being. |
What's value of that cell in db? |
The value of the cell in db is '0000-00-00'. I have read the following in mySql documentation:
|
I am currently using in my.ini:
So I am in sql.mode="" |
This is an interesting article: Incorrect date value |
So I am NOT running in strict mode and therefore the mySql is allowing these '0000-00-00' dates. I think the solution to avoid this issue completely is simply to set the default date in the php, whether in the controller or in the views for unfilled dates to: (new \DateTimeImmutable('now'))->format(..user.'s date...choice). ....... which gets converted to mySql's YYYY-mm-dd This will ensure that the current date is at least in the mySql field and in any datepicker and this will avoid the '0000-00-00' issue completely. So forms have a default date of the current date. |
The above solution works but I will leave this open for discussion. |
@roxblnfk do you know how to solve it in Cycle? |
If you can point me in the right direction I would appreciate it. I will raise an issue in Cycle. |
Closing since it's not issue of the Yii framework itself. |
What steps will reproduce the problem? Presenting a DateTimeImmutable as a string in a view using:
eg. ($client->getClient_birthdate())->format($datehelper->style())
What is the expected result? A legitimate date.
What do you get instead? -0001-11-30
Additional info
The text was updated successfully, but these errors were encountered: