2

I have a custom attribute called customer_products_changedate it saves the date when I link a product to it and it's linked to the customer.

How do I get the customers, filtered by that attribute, but only if the date in the attribute is older than 14 days.

I currently have this:

$collection = Mage::getResourceModel('customer/customer_collection');
$collection->addAttributeToFilter('customer_products_changedate', 'OLDER THAN 14 DAYS');

Would also be nice how to do delete those attributes than, not the users, just those attribute entries.

5
  • It's not a duplicate, because how are we supposed to know what the difference between gt and lt is?
    – Arnold
    Jul 20, 2017 at 13:29
  • I think this doesnt makes a difference. lt is less than and gt is greater then. However ... you found a solution for this :)
    – sv3n
    Jul 20, 2017 at 13:35
  • 1
    Yes I agree, but still... There is no documentation of Magento. So I think questions like these will make Magento more accessible to people that are new to Magento. There are also many different variations of this question (PHP) at Stackoverflow. how to filter dates, older, newer, in a range. ect. ect. Why shouldn't it be the same with Magento?
    – Arnold
    Jul 20, 2017 at 13:37
  • Ok, no wonder Magento.stackexchange sucks so much. they remove usefull questions. lol.
    – Arnold
    Jul 21, 2017 at 7:17
  • It sucks so much that people help others for free? Ahh, ok. Your last questions were answered within a hour .... and it's not removed, just flagged as duplicate ...
    – sv3n
    Jul 21, 2017 at 8:23

2 Answers 2

5

Get the date which was 14 days ago.

$date = date('Y-m-d', strtotime('-14 day'));

Now filter the collection with the date.

$collection->addFieldToFilter(
    'customer_products_changedate',
    array(
        'lt'=>$date
    )
); 
2
  • Thank you, can you also tell me how to delete those customer_products_changedate from that customer?
    – Arnold
    Jul 20, 2017 at 12:38
  • What value you want to save instead of the already present date? You can load the customer and change field value and save the customer.
    – amitshree
    Jul 20, 2017 at 12:42
0

Get date

$to= Mage::app()->getLocale()->date()->sub(14,Zend_Date::DAY);
$to=$to->toString('yyyy-MM-dd');

Add that in filter:

$collection->addFieldToFilter(
    'customer_products_changedate',
    array(
        'lt'=>$to
    )
); 

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