0

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?

0

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);
        }
| improve this answer | |
  • Thanks, my problem was that I was not using the correct magic setter.... I hate it when I have to guess what the name of the attribute is for a setter... Thanks anyway. It works now, but I will accept your answer since you took your time to try and help. – user1137313 Nov 6 '15 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.