In your extension’s Form.php:
For Example: app/code/local/CompanyName/ModuleName/Block/Adminhtml/ModuleName/Edit/Tab/Form.php
Add the following code:
$dateFormatIso = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $fieldset->addField('start_date', 'date', array( 'name' => 'start_date', 'label' => Mage::helper('events')->__('Start Date'), 'title' => Mage::helper('events')->__('Start Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'input_format' => $dateFormatIso, 'format' => $dateFormatIso, 'time' => true ));
The key things to make it work are the “input_format”, “format”, and “time” parameters in the addField array. Setting the “time” variable to “true” makes the time input fields appear in the date selector pop-up.
Thank you Axel. I have saved my time
Is it possible to specify the timezone for this datetime field?
Hi Roger. I don’t believe so. You’ll probably have to extend the date field and create a custom one that allows for defining the timezone within the field.
I am doing the same in my _prepareForm() and when the form is posted i can see values – [from_date] => 2015-09-10 02:02:00
but the values are not getting saved in db.
My db field is this – `from_date` DATETIME NOT NULL,
Do u have idea idea what is the issue.
Did you create the from_date column in the database yourself?
If so, be sure you’re deleting everything under your var/cache folder. Magento sometimes caches the database structure for tables and it won’t pick up on new columns unless you flush the cache.
Is it possible to extend the date of a category in magento without going through the codes.
i created a sale category and the date i set it to will expire on the 30th of this month.Please how can i extend the date of the sale category without going to individual items to change the date and without using codes.
I would recommend using the Catalog Price Rules to apply a discount to the entire category instead of setting a sale price to each individual item.
Go under Promotions > Catalog Price Rules and set a rule that applies to your category.
if i need to show time with date picker in the front end, then what to do??
Thank you very much!
Very useful post