Model – Custom Model Date Field Not Saving Current Time in Table

datemodelmoduletable

I have create an model in magento at a custom module and in that model i have create table and that table have a date field and i want save my current date in that date field but it becomes inserted value null at that table

Table Sql:

CREATE TABLE IF NOT EXISTS `social` (
  `social_id` int(10) NOT NULL AUTO_INCREMENT,
  `image` text NOT NULL,
  `likes` int(10) DEFAULT NULL,
  `caption_text` text,
  `comments` int(10) DEFAULT NULL,
  `insert_time` date DEFAULT NULL,
  PRIMARY KEY (`instagram_id`),
  KEY `likes` (`likes`,`insert_time`),
  KEY `comments` (`comments`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;

Model insert code:

$data=array(
'image'=>$url,
'likes'=>$item->likes->count,
'caption_text'=>$item->caption->text,
'comments' =>$item->comments->count,
'insert_time'=>date ('Y-M-d'), 
);
$model=Mage::getModel('social/social')->addData($data);
$model->save();

Why in date filed insert_time save all value as Null instead of current date?

Best Answer

date('Y-M-d') will produce 2015-Jan-14 and you probably want date('Y-m-d') which will give you 2015-01-14