Magento Set Grid to Filter Automatically by Current Day using Existing Datetime Column in Grid
- by Tegan Snyder
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