I have an attribute with code "open_date", for customer address. data is being saved in db in format 29/01/2017, I am trying to apply filter to get store opening in next two weeks. What I have tried is

$fromDate = Mage::getModel('core/date')->date('d/m/Y');//    06/01/2017
$toDate = date('d/m/Y', strtotime("+2 week"));//             20/01/2017

$collection = Mage::getResourceModel('customer/address_collection');
$collection->addAttributeToFilter('open_date', array('from' => $fromDate, true));
$collection->addAttributeToFilter('open_date', array('to' => $toDate, true));

and also

$collection = Mage::getResourceModel('customer/address_collection');
$collection->addAttributeToFilter('open_date', array('from'=>$fromDate, 'to'=>$toDate));

and also

$collection->addAttributeToFilter('open_date', array('gteq' => $fromDate));
$collection->addAttributeToFilter('open_date', array('lteq' => $toDate));

And have tried some other methods.

$coutn = count($collection);
$ids = $collection->getAllIds();

count and ids have not correct records. with above dates, count should be two(2), but it has 10 in it.


1 Answer 1


Please check this :

$collection = Mage::getResourceModel('customer/address_collection');

$fromdate = Mage::app()->getLocale()->date($data['date'],Zend_Date::DATE_SHORT, null, false);
$from = $fromdate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

$todate = Mage::app()->getLocale()->date($data['date'],Zend_Date::DATE_SHORT, null, false);
$to = $todate->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

$collection->addFieldToFilter('created_at', array('from' => $from, 'to' => $to));
  • 1
    The key here is to use Varien_Date::DATETIME_INTERNAL_FORMAT and not 'd/m/Y' so that MySQL recognizes the date format Jan 6, 2017 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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