Syntax of timestamp
How do I insert values in a database field with type timestamp? I am 开发者_如何学Godoing this way in CodeIgniter.
$user_poll_query=array('description'=>$poll_query,
'creator_id'=>$user_id,
'valid_from'=>date('Y-m-d H:i:s','1299762201428'),
);
$this->db->insert('sl_polls',$user_poll_query);
but in the database I am getting 0s (0000-00-00 00.00.00)
.
Well it looks like you are using
'valid_from'=>date('Y-m-d H:i:s','1299762201428'),
but your date isn't in the format Y-m-d H:i:s.
Try a different date format or convert the UNIX timestamp to a date your db can use.
Hope that helps!
On the assumption that you are using MS SQL Server, I think that your problem is that you don't get the idea of a timestamp type in SQL Server. This isn't a "real" time. A Timestamp is a data type that exposes automatically generated, unique binary numbers within a database. timestamp is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The timestamp data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime data type.
See http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx
You should use a Date, Time, or DateTime field to track when something was done.
hth
Mike Irwin
精彩评论