Skip to content

Instantly share code, notes, and snippets.

@webdawe
Last active July 1, 2018 10:46
Show Gist options
  • Save webdawe/93f07d23aac99e2b46a4c49c492f4cb0 to your computer and use it in GitHub Desktop.
Save webdawe/93f07d23aac99e2b46a4c49c492f4cb0 to your computer and use it in GitHub Desktop.
<?php
//Magento 2
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
$currentDate = $this->_timezone->date()->format('Y-m-d H:i:s');
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToFilter('expiry_date', array('or'=> array(
0 => array('date' => true, 'from' => $currentDate),
1 => array('null' => true))
), 'left');
//Magento 1
$currentDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$productCollection->addAttributeToFilter('expiry_date', array('or'=> array(
0 => array('date' => true, 'from' => $currentDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment