I have had similar issue with Date filter :)
The way date time instantiated in the form like that
Step 1:-
In Block Form class Mage_CatalogSearch_Block_Advanced_Form
public function getDateInput($attribute, $part = 'from')
{
$name = $attribute->getAttributeCode() . '[' . $part . ']';
$value = $this->getAttributeValue($attribute, $part);
return $this->_getDateBlock()
->setName($name)
->setId($attribute->getAttributeCode() . ($part == 'from' ? '' : '_' . $part))
->setTitle($this->getAttributeLabel($attribute))
->setValue($value)
->setImage($this->getSkinUrl('images/calendar.gif'))
->setFormat('%m/%d/%y') //So you need change the Format here !!!!!
->setClass('input-text')
->getHtml();
}
So you need to change the Date format for the calendar in the line ->setFormat('%m/%d/%y')
Then its used in the method below to generate the block
$block = $this->getLayout()->createBlock('core/html_date');
$this->setData('_select_block', $block);
and in that block class Mage_Core_Block_Html_Date
Line 40: $displayFormat = Varien_Date::convertZendToStrFtime($this->getFormat(), true, (bool)$this->getTime());
.......
Line53: ifFormat : "' . $displayFormat . '",
Step 2:-
In the advanced search collection class Mage_CatalogSearch_Model_Resource_Advanced_Collection
You need to modify this method to allow the new locale or the new datatime format you needed !
Line43: public function addFieldsToFilter($fields) {
.......
.......
.......
.......
Line96: if (!Zend_Date::isDate($conditionValue['from'])) {
.......
Line109:if (!Zend_Date::isDate($conditionValue['to'])) {
.......
}
Now You need to modify those 2 lines with the new datetime format you change the search block to allow this method to be validated
For instance i modified the Javascript calendar format to be %d-%m-%Y which will produce Date in the calendar like ( 25-12-2014 )
Then i modified The method in the above collection class to be like this
if (!Zend_Date::isDate($conditionValue['from'], 'd-m-Y' )) { // I added the format for the validation
.......
.......
if (!Zend_Date::isDate($conditionValue['to'], 'd-m-Y' )) { // same as above one
step 3:-
Change those value of date inputs in the class Mage_CatalogSearch_Model_Resource_Advanced_Collection
to whatever format or locale.
Everything works fine with that.
I have made small module that rewrite the 2 classes you need to modify based on the locale you need
Check it out https://github.com/Meabed/magento-advanced-search-datetime-field
Regards !
Don't forget about locale! As all other examples can cause issues for people from different time zones.
Mage::app()->getLocale()->date()
inside date()
you can put any date and call method ->toString()
with some param.
Pattern examples you can find in Varien_Date
const DATETIME_INTERNAL_FORMAT = 'yyyy-MM-dd HH:mm:ss';
const DATE_INTERNAL_FORMAT = 'yyyy-MM-dd';
const DATETIME_PHP_FORMAT = 'Y-m-d H:i:s';
const DATE_PHP_FORMAT = 'Y-m-d';
or use any you like.
For example for current time full call will look like this:
Mage::app()->getLocale()->date()->toString(Varien_Date::DATE_INTERNAL_FORMAT);
Best Answer
To change visible date format in date inputs You need to set proper Interface Locale in the Account Setting.
After that You will see changes on the Edit Product Page.
To change dates in frontend catalog go to: Stores > Configuration > Catalog > Catalog and find Date & Time Custom Options
There you can configure date format on store front catalog.