Dima Ulyanov Sat Oct 16 17:06:27 -0400 2010

Subject: Insert now() to the datetime column

users (id int, name varchar(10),created datetime);

I need this query:
insert into users(id,name,created) values(id,'test',now());

$user = new User();
$user->name = 'test';
$user->created = 'now()';
And i got error.

How i can tell model that field 'created' is datetime and to insert directly now() or to make function on_insert that can do this?

Keith Thibodeaux Sat Oct 16 19:14:23 -0400 2010

Try using the TIMESTAMP column type instead of DATETIME. I ran into the same issues, and TIMESTAMP seems to work perfect.

TIMESTAMP's default format:

With MySQL (not sure about others) you can set the column to have a default value of current_TIMESTAMP without having any PHP telling it to do so (this can only be done with TIMESTAMP).