Create a new date field at any database and save the record

In u r Form u need to add this code to make a date field to put the date information in to it

$dateFormatIso = Mage::app()->getLocale() ->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
            $fieldset->addField('created_time', 'date', array(
                'label' => Mage::helper('news')->__('Create Date'),
                'title' => Mage::helper('news')->__('Create Date'),
                'name' => 'created_time',
                'image' => $this->getSkinUrl('images/grid-cal.gif'),
                'format' => $dateFormatIso,
                'value' => 'created_time',
                //'required' => true,
               ));

Use this below code to u r controller to save it into the database

$postData = $this->getRequest()->getPost();
                $newsModel = Mage::getModel('news/news');


                if($postData['created_time'] != NULL )
                {
                    $datecustom = Mage::app()->getLocale()->date($postData['created_time'], Zend_Date::DATE_SHORT);
                   // print_r($datecustom);die();
                   // $model->setStartDate($date->toString('YYYY-MM-dd HH:mm:ss'));
                }


                $newsModel->setId($this->getRequest()->getParam('id'))
                  //  ->setTitle($postData['title'])
                  //  ->setContent($postData['content'])
                  //  ->setStatus($postData['status'])
                  //  ->setRemarks($postData['remarks'])
                    ->setcreated_time($datecustom->toString('YYYY-MM-dd HH:mm:ss'))
                    ->save();
Advertisements

Tagged: , ,

One thought on “Create a new date field at any database and save the record

  1. Free Porn November 15, 2010 at 7:38 pm

    High quality info here! Keep up the great work. I love the feelings being expressed.

Comments are closed.

%d bloggers like this: