Skip to content
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

Date from mysql is wrong converted to Nette/Utils/DateTime #169

Open
MichalKalita opened this issue May 19, 2017 · 2 comments
Open

Date from mysql is wrong converted to Nette/Utils/DateTime #169

MichalKalita opened this issue May 19, 2017 · 2 comments

Comments

@MichalKalita
Copy link

@MichalKalita MichalKalita commented May 19, 2017

  • bug report? yes
  • feature request? no
  • version: 2.4.2

Description

In my application, I read date from database, and write it to other table.
Date "0000-00-00 00:00:00" is bad converted to php, and cannot be saved back to mysql.

Exception:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '-0001-11-30 00:00:00' for column 'date' at row 1

Steps To Reproduce

In database I have date "0000-00-00 00:00:00", data type is datetime not null. InnoDB.
I use simple NDBT select

$row = $this->table(..)->wherePrimary(...)->fetch();
echo $row->date; // prints "-0001-11-30 00:00:00"
// and write it back
$this->table(...)->wherePrimary(...)->update(['date' => $row->date]); // it throws exception, mysql cannot save this date

PHP 7.1.2, mysql 5.6.22, I use InnoDB for all tables.

@hrach
Copy link
Contributor

@hrach hrach commented May 19, 2017

0000-00-00 00:00:00 is not a valid datetime; make to column nullable. such value may cause problems also directly in the mysql.

@h4kuna
Copy link
Contributor

@h4kuna h4kuna commented Jun 30, 2017

For interest Mysql 5.7 does not allow invalid datetime "0000-00-00 00:00:00". Let's prepare your databese :) Like @hrach recommended you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.