Magento Set Grid to Filter Automatically by Current Day using Existing Datetime Column in Grid
Posted
by Tegan Snyder
on Stack Overflow
See other posts from Stack Overflow
or by Tegan Snyder
Published on 2010-03-24T15:38:19Z
Indexed on
2010/04/06
20:43 UTC
Read the original article
Hit count: 353
In Magento I'm creating a custom module and would love to be able to filter automatically by the datetime column so that the intial grid listing shows only entities related to "todays" date.
Here is my datetime column:
$this->addColumn('ts', array(
'header' => $hlp->__('Activated'),
'align' => 'left',
'index' => 'ts',
'type' => 'datetime',
'width' => '160px',
));
I'm think there should be a way for me to just add a filter to the collection like so:
$now = Mage::getModel('core/date')->timestamp(time());
$dateTime = date('m/d/y h:i:s', $now);
$collection = Mage::getModel('mymodule/items')->getCollection()
->addFieldToFilter('ts', $dateTime);
But this doesn't work?
Am I using the wrong filter? My "ts" field in the database is a "datetime" field, but the default magento "From: " - "To:" date range selectors don't use hours, minutes, seconds.
Any ideas?
Thanks, Tegan
© Stack Overflow or respective owner