php-activerecord icon indicating copy to clipboard operation
php-activerecord copied to clipboard

Invalid datetime format

Open fenixphp opened this issue 11 years ago • 13 comments

recentactivity datetime NOT NULL

if I do

  $this->info = account\models\user\Info::find_by_email($this->data['USRIE'])  

  ActiveRecord\DateTime::$DEFAULT_FORMAT = 'db';
  $this->info->recentactivity->setTimestamp(time());
  $this->info->save();

or

  $this->info->recentactivity->setTimestamp(time());
  $this->info->save();

or

  $this->info->recentactivity = date('Y-m-d H:i:s');
  $this->info->save();

or

  $this->info->recentactivity->setDate(date('Y'), date('m'), date('d'));
  $this->info->save();

or

  $this->info->recentactivity->setDate(date('Y'), date('m'), date('d'));
  $this->info->recentactivity->setTime(date('H'), date('i'), date('s'));
  $this->info->save();

as a result

 'SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2014-06-08 04:12:19 GST' 

whence GST?

fenixphp avatar Jun 08 '14 00:06 fenixphp

Decision:

MysqlAdapter.php

class MysqlAdapter extends Connection
{
    static $datetime_format = 'Y-m-d H:i:s'; // add this

fenixphp avatar Jun 10 '14 08:06 fenixphp

I thought this problem looked familiar when I first saw it and the solution is definitely familiar.

I recently added the following lines in my initialising code (as opposed to editing the classes directly)

//ensure that the timestamps support MySQL by removing the timezone
//may not be necessary in future versions, required here for IIS compatibility
\ActiveRecord\Connection::$datetime_format = 'Y-m-d H:i:s';

willpower232 avatar Jun 10 '14 08:06 willpower232

as I understand this string in the class should be to avoid such situations. на сколько я понимаю то такая строка в классе должна быть, чтобы исключить такие ситуации.

fenixphp avatar Jun 10 '14 09:06 fenixphp

Indeed it probably should be but I didn't want to overwrite the change when I uploaded a new version should the code necessary not be there and I didn't have the time to see if there was already a pull request for this.

willpower232 avatar Jun 10 '14 09:06 willpower232

I said it is rather for developers AR ... :)

я говорил это скорей для разработчиков AR ... :)

date and time format for the most part of MySQL standard and it makes sense to introduce a line on an ongoing basis, or something like that to avoid such situations.

формат даты и времени для MySQL по большей часть стандартный и имеет смысл ввести такую строку на постоянной основе, или что то подобное для избегания таких ситуаций.

fenixphp avatar Jun 10 '14 10:06 fenixphp

This was almost addressed in #317 before I vanished but never got merged. Unless @andyleap wants to have a go, I'll block some time next week to refactor his PR and resubmit.

al-the-x avatar Jun 28 '14 02:06 al-the-x

Sorry, unless @andyleap wants to take a swing at cleaning up #317, I meant.

al-the-x avatar Jun 28 '14 02:06 al-the-x

I just updated my datetime branch so it's now based on current master, Travis build checks out: https://travis-ci.org/andyleap/php-activerecord

andyleap avatar Jun 28 '14 03:06 andyleap

I haven't looked at it in a while, as I'm not using phpActiveRecord right now, but if there's anything I need to redo in there, I may have some time over the weekend to work on it.

andyleap avatar Jun 28 '14 03:06 andyleap

This is still a problem today. I cannot (and should not) overwrite static class properties. How to fix this without creating modifying classes? Isn't there any config method available to set the format for datetimes?

josfaber avatar Apr 09 '16 07:04 josfaber

Honestly, don't expect anything from me either. The authors on this project have shown repeated that they don't care about this problem, and I haven't touched PHP code in nearly a year now.

andyleap avatar Apr 10 '16 01:04 andyleap

Oh damn, this thing is breaking a large project of mine and I have to get it back up as soon as possible. Is there any work around for it?

Invalid datetime format: 1292 Incorrect datetime value: '-0001-12-01 21:29:43'

With the following setting in the Connection class:

static $datetime_format = 'Y-m-d H:i:s';

pultho avatar Apr 26 '17 19:04 pultho

thats a very weird datetime value to have, is the input into that query correct? it must be year month day.

this might be helpful: http://stackoverflow.com/questions/22218795/incorrect-datetime-value-1-1-0001-120000-am-for-column-call-time-at-row-1

willpower232 avatar Apr 28 '17 22:04 willpower232