I have a product collection from Monday to Sunday (using attributes date_from and date_to). I want to show products from current week but I need to exculde the current date products.

I have


In this collection I want to exclude the current day, how can I do it?

3 Answers 3


You can combine multiple conditions in addFieldToFilter() which will combined with OR.

Additionally, I'd suggest you to use the date comparison operators instead of gteq and lteq.

For the date_from attribute, the following will filter all products that have date_from between monday and yesterday OR between tomorrow and sunday (if that's what you want):

    ['attribute' => 'date_from', 'condition' => array(
        'date' => true, 'from' => 'this week monday 0:00', 'to' => 'yesterday 23:59')],
    ['attribute' => 'date_from', 'condition' => array(
        'date' => true, 'from' => 'tomorrow 0:00', 'to' => 'this week sunday 23:59')]);

"this week monday 0:00" will be parsed with strtotime(), so it is a valid value. The times 0:00 and 23:59 are necessary because there is a bug in Varien_Db_Adapter_Pdo_Mysql::_prepareSqlDateCondition that treats date equal to datetime

If you want to learn more about the conditions that you can use in addAttributeToFilter() and addFieldToFilter(), take a look at Varien_Db_Adapter_Pdo_Mysql::prepareSqlCondition() - the core code is often the best documentation source.

I also explained addFieldToFilter in a bit more detail here: addFilter vs addFieldToFilter


Instead of 'gteq' use 'gt'. It would exclude the current date for your if the period your are trying to fetch the collection for is in the future.

  • gt will work if today is monday what if today is tuesday.then gt last monday will give current date also Sep 8, 2014 at 19:11

I did not get a proper solution,

So, I suggest to divide the collection into two collections:

Step1: 1st collection from "this week Monday" date to yesterday

Step2: and other collection from tomorrow to "next week Sunday"

Step3: union two collection using union()



$collection1->addAttributeToFilter('created_at', array(
    'from' => $thisweekmonday,
    'to' => $yesterday,
    'date' => true, 
$collection2->addAttributeToFilter('created_at', array(
    'from' => $tomorrow,
    'date' => true, 

$collection1Select = $collection1->getSelect();
$collection2Select= $collection2->getSelect();

$mergedCollection = $collection1Select->union(array($collection2Select));

Your final collection is $mergedCollection

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.