You can see the below code to add start date and end date field in admin custom module(Which is created using module creator).
Create two fields “start_date” and “end_date” in database table of your custom module.
$dateFormatIso = Mage::app()->getLocale() ->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$fieldset->addField(’start_date’, ‘date’, array(
‘label’ => Mage::helper(‘banner’)->__(‘Start Date’),
‘title’ => Mage::helper(‘banner’)->__(‘Start Date’),
‘name’ => ’start_date’,
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘format’ => $dateFormatIso,
‘value’ => ’start_date’,
//’required’ => true,
));
$fieldset->addField(‘end_date’, ‘date’, array(
‘label’ => Mage::helper(‘banner’)->__(‘End Date’),
‘title’ => Mage::helper(‘banner’)->__(‘End Date’),
‘name’ => ‘end_date’,
‘image’ => $this->getSkinUrl(‘images/grid-cal.gif’),
‘format’ => $dateFormatIso,
‘value’ => ‘end_date’,
//’required’ => true,
));
Copy and paste the above code to your custom_module/block/adminhtml/custom_module/Edit/Tab/Form.php file
and than open controller of the same module
Path :: custom_module/controllers/adminhtml/custommoduleController.php
Add below lines before $model->save() to save dates in
function saveAction().
if($data['start_date'] != NULL )
{
$date = Mage::app()->getLocale()->date($data['start_date'], Zend_Date::DATE_SHORT);
$model->setStartDate($date->toString(‘YYYY-MM-dd HH:mm:ss’));
}
if($data['end_date'] != NULL)
{
$date1 = Mage::app()->getLocale()->date($data['end_date'], Zend_Date::DATE_SHORT);
$model->setEndDate($date1->toString(‘YYYY-MM-dd HH:mm:ss’));
}
January 12, 2010
Subscribe to:
Post Comments (Atom)
hi, the exact thing which i was searching is here. Thanks. And still i have a issue, i could see the format changing while using this $date1->toString(‘YYYY-MM-dd HH:mm:ss’), but it does not saved into $model->setEndDate() methond, my table filed names or exactly same as yours. Could find why its happening?
ReplyDeletethanks. very helpful article.
ReplyDeleteregards,
Riki Risnandar
Thanks for the information regarding date....
ReplyDeletehelped a lots for custom date of birth field storing process
Super working fine.. Thanks dude..
ReplyDeleteHello friend! this code works in 3 step checkout, shipping method? For the customer to schedule a date and time for delivery, you know? Please help me! Come back soon! Thank you!
ReplyDeleteThanks a lot Darling...
ReplyDeleteif the date is one day before the selected one try
ReplyDeleteMage::app()->getLocale()->date($data['start_date'], Zend_Date::DATE_SHORT, null, false);
set 'useTimezone' to False in
/app/code/core/Mage/Core/Model/Locale.php
date($date = null, $part = null, $locale = null, $useTimezone = true)
Your post is very useful, and Comtempo's comment put a cherry on the top of it.
DeleteThank you very much!!!!
ReplyDeleteHere is a shorter way to transform the date fields values before saving. In the saveAction after getting the post data do this ($data is what is sent through post):
ReplyDelete$data = $this->_filterDates($data, array('start_date', 'end_date'));
Tested on CE 1.7 and 1.8. Most likely it works for other versions as well.
Thanks Marius.. great
DeleteThanks.Very helpful
ReplyDeleteVery nice blogs.We hope to really understand that the lot of new information.
ReplyDeleteInformatica Training in Chennai
This post is really nice and informative. The explanation given is really comprehensive and informative..
ReplyDeleteSAS Training In Chennai
i need to change date format like (mm-dd-Y to dd-mm-Y)in magento rest api. how can i do plz help me
ReplyDeleteThis post is really nice and informative.amazon-web-services training in chennai
ReplyDeleteThis post is really nice and informative.
ReplyDeleteamazon-web-services training in chennai
This post is really nice and informative.
ReplyDeletesas training in chennai
Thanks.Very helpful...
ReplyDeleteselenium training in chennai
• Good article! There is a great need for more in-depth reviews of certain products and technologies. Your tips are really helpful for anybody who wants to create reviews of any type. Great job. Thanks.
ReplyDeleteqtp training in chennai
nice articles keep posting - Best Hadoop Training in Chennai
ReplyDeleteBest MSBI Training in Chennai
Thank you so much for sharing... game killer ios no jailbreak
ReplyDelete
ReplyDeleteYouExcellent Artical.Thank you very much for your hard work.
I have read your blog its very attractive and impressive.
UNIX Shell scripting training in chennai
ORACLE apps finance training in chennai
Informatica Online Training