我有一個自定義集合,我希望通過創建日期和Het條目篩選產生「昨天」Magento的過濾器收集的創建時間(今天,昨天,周,小時等)
集合條目
//dates are set in controller using
setCreatedTime(Mage::getModel('core/date')->gmtDate());
創建昨天(不工作)
//3 products items Yesterday
//below filtering outputs incorrect entries
$collection = Mage::getModel('things/things')->getCollection();
我試過了,但輸出不正確的條目;
//thought strtotime('yesterday') would work..
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('yesterday'))));
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('-1 day'))));
$collection->addFieldToFilter('created_time', array('from'=> strtotime('-1 day', time()),'to'=> time(),'datetime' => true));
$fromDate = date('Y-m-d H:i:s', strtotime($fromDate));
$toDate = date('Y-m-d H:i:s', strtotime($toDate));
$collection->addFieldToFilter('created_time', array('from'=>$fromDate, 'to'=>$toDate));
造就了今天(當天)(作品)
//5 products items today with timestamp 2016-05-01 05:22:53
//below filtering outputs correct entries
$collection = Mage::getModel('things/things')->getCollection();
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('today'))));
創過去一週(作品)
//23 products items with timestamps for this week
//below filtering outputs correct entries
$collection = Mage::getModel('things/things')->getCollection();
$collection->addFieldToFilter('created_time', array('gt' => Mage::getModel('core/date')->date('Y-m-d H:i:s', strtotime('-1 week'))));
Thanks @Ash for your input – BENN1TH