Oktay Safak Sun Mar 13 16:16:07 -0400 2011

Subject: Saving Date to Mysql Problem

My php code is :

$news->create_date = date('Y-m-d H:i:s');

But i am getting error :
Fatal error: Uncaught exception 'ActiveRecord\DatabaseException' with message '22007, 1292, Incorrect datetime value: '2011-03-13 21:51:41 EET' for column 'create_date' at row 1

i tired lot of case but same error

Taylor Otwell Mon Mar 14 09:23:42 -0400 2011

Did you know you can just name your DATETIME column "created_at" and PHP ActiveRecord will update it for you automatically?

Oktay Safak Mon Mar 14 11:43:34 -0400 2011

thnks for your reply but what about another column name?

Taylor Otwell Mon Mar 14 11:46:24 -0400 2011

As far as I know, PHP-AR doesn't support custom column names for the automatic timestamps. This probably wouldn't be hard to add though.

What data type is your column in the database? DATETIME?

Oktay Safak Mon Mar 14 18:01:45 -0400 2011

i dont want to automatic timestamp. i need to save manuel. My columns data type is DATETIME.

Marcellus Barrus Tue Mar 29 19:34:05 -0400 2011

Were you able to find a solution.

I have a column that is also DATETIME within mysql.

I have a date updated column that I set using date( "Y-m-d H:i:s" );

When saving or updating I get the following error.

Incorrect datetime value: '2011-03-29 17:23:51 MDT' for column

Where is the MDT coming from? It isn't in my code.


Marcellus Barrus Wed Mar 30 13:09:55 -0400 2011

What's the point of having Config::set_date_format() and Config::get_date_format() if they are never used? AND date formatting is hard coded to 'Y-m-d H:i:s T'. MySQL doesn't take the 'T' value within their DATETIME column.

I don't know if I messed something up more, but I fixed it by changing all the hard coded 'Y-m-d H:i:s T' to Config::instance()->get_date_format()

and updated my config to the following:

ActiveRecord\Config::initialize( function( $cfg ) use ( $connections ) {
$cfg->set_date_format( "Y-m-d H:i:s" );

The three files I changed are Column.php, Connection.php and Model.php

Yoan B Fri Apr 01 02:37:04 -0400 2011

Which version are you using?

`(g|s)et_date_format` are deprecated

and the format is not the one you mention anymore:

andreas pag Sat Jul 02 09:41:33 -0400 2011

I think Marcellus Barrus has the answer.

If you don't modify these files i don't think you can fix the issue with the date. Tried the created_at column which is supposed to solve the problem but it didn't work.

Working with the latest stable version available for download from wsite.

Anyone found a diff solution? (other than the one Marcellus posted)

Manuel de la Higuera Thu Jun 28 11:10:12 -0400 2012

I would go with this:
$news->create_date = date(DATE_RFC822)

asava samuel Thu Mar 07 05:05:49 -0500 2013

Manuel de la Higuera

Here is an ORM that works with MySQL

Sven Leuschner Fri Mar 08 05:47:06 -0500 2013

Hm.. somewhere between the earlier posts and today this behaviour was changed -
my code

$user->update_attributes(array('lastactivitydate' => strftime("%Y-%m-%d %H:%M:%S")));

and it works likewise if I exchange date for strftime - and change the format-string

Sanchit Bhatnagar Thu Feb 12 22:06:18 -0500 2015

Here is how to fix it:

ActiveRecord\Connection::$datetime_format = 'Y-m-d H:i:s';
Jos Faber Wed Dec 07 08:21:47 -0500 2016

That static property is not available anymore in stable build 1.0, so that won't work.
The format is, as Marcellus pointed out 5 years ago, hardcoded.
Any other solutions other than changing core code?

Stefan Djokic Wed Oct 11 11:22:32 -0400 2017

For all of those still struggling with this issue.
I've made a pull request which will hopefully help you solve this.