setting codeigniter mysql datetime column to time() always sets it to 0

Posted by Jake on Stack Overflow See other posts from Stack Overflow or by Jake
Published on 2010-05-13T21:55:47Z Indexed on 2010/05/13 22:24 UTC
Read the original article Hit count: 271

Filed under:
|
|
|
|

Hi guys. I'm using Codeigniter for a small project, and my model works correctly except for the dates. I have a column defined:

created_at datetime not null

and my model code includes in its array passed into db->insert:

'created_at' => time()

This produces a datetime value of 0000-00-00 00:00:00.

When I change it to:

'created_at' => "from_unixtime(" . time() . ")"

it still produces the 0 datetime value.

What am I doing wrong? How can I set this field to the given unix time? Also, I know mysql sets TIMESTAMP columns automatically for you - I'm not interested in that solution here.

So far I can't find a complete example of this on the web.

© Stack Overflow or respective owner

Related posts about codeigniter

Related posts about mysql