Did you know you can just name your DATETIME column "created_at" and PHP ActiveRecord will update it for you automatically?
thnks for your reply but what about another column name?
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?
i dont want to automatic timestamp. i need to save manuel. My columns data type is DATETIME.
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.
Thanks.
Marcellus
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_model_directory('/home/DB_Config/models');
$cfg->set_connections($connections);
$cfg->set_date_format( "Y-m-d H:i:s" );
});
The three files I changed are Column.php, Connection.php and Model.php
Which version are you using?
`(g|s)et_date_format` are deprecated
https://github.com/kla/php-activerecord/blob/master/lib/Config.php#L265-281
and the format is not the one you mention anymore:
https://github.com/kla/php-activerecord/blob/master/lib/Config.php#L75
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)
I would go with this:
$news->create_date = date(DATE_RFC822)
Manuel de la Higuera
Here is an ORM that works with MySQL
https://www.kellermansoftware.com/p-47-net-data-access-layer.aspx
Hm.. somewhere between the earlier posts and today this behaviour was changed -
my code
$user=User::find($_SESSION['IDuser']); $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
Here is how to fix it:
ActiveRecord\Connection::$datetime_format = 'Y-m-d H:i:s';
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?
For all of those still struggling with this issue.
I've made a pull request which will hopefully help you solve this.
https://github.com/jpfuentes2/php-activerecord/pull/585
(1-14/14)
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