Magento 1.9 – Set Date Value to an Attribute in a Custom Model

dateeavmagento-1.9

So I have my EAV called mymodel and one of it's fields/attributes is called "enddate" of date type. Now, when I create a new object, and I want to set the value of this "enddate"… I just can't. The saving works fine, but the value saved into the database is bogus, so not the value I want to set. So this here does not work

$mynewitem = Mage::getModel('mypath/mymodel');
$mynewitem->setEndDate('2011-03-05');//(I also tried with time attached hh:mm:ss)
$mynewitem->save();

How do I save this date inside my model from Magento?
I actually have a form (frontend) where I enter the date and Post it, so it's going to be text.

I also tried

$mynewitem = Mage::getModel('mypath/mymodel');
$dtx1 = Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s','now');
$mynewitem->setEndDate($dtx1);
$mynewitem->save();

But what format should I use? How to set it?

Best Answer

Try below code for save...

    $dateValue = '2011-03-05'
    $value = date('Y-m-d', strtotime($dateValue));
    $mynewitem->setEndDate($value);

    try{
           $mynewitem->save();
        }catch (Exception $e) {
            Mage::logException($e);
        }