使用addAttributeToFilter获取日期的月份

时间:2014-06-17 14:10:18

标签: magento collections

是否可以使用addAttributeToFilter获取日期的月份?我需要得到一些客户的出生日期,但没有任何工作。我正在尝试下面的代码:

<?php

$collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('firstname')->addAttributeToSelect('lastname')->setOrder('firstname', 'ASC')->addAttributeToFilter('dob', array('like'=>'03'));

foreach ($collection as $client) { 

      echo  $client->getSelect()." ". $client->getData('firstname')." ".$client->getData('lastname')."<br>";
}
?>

1 个答案:

答案 0 :(得分:0)

试试这个

<?php$collection
$collection = Mage::getModel('customer/customer')->getCollection()
            ->addAttributeToSelect('firstname')
            ->addAttributeToSelect('lastname')
            ->addAttributeToFilter('dob', array('like'=>'%03%'))
            ->setOrder('firstname', 'ASC');

foreach ($collection as $client) { 

      echo  $client->getData('firstname')." ".$client->getData('lastname')."<br>";
}
?>