0

I want to collect the records from 10PM to 5AM of wishlist data. I have already created a module and not sure how to filter the records by this timeframe.

The wishlist table contains a field called Updated at. Now how can I use this field to filter the records?

Can anyone please guide me on that?

Any help will be appreciated.

Error:

Fatal error: Uncaught Error: Call to undefined function thimma\mymodule\Model\now() in /var/www/html/thimmajan3/thimma/app/code/thimma/mymodule/Model/Salesorder.php:28 Stack trace: #0 /var/www/html/thimmajan3/thimma/app/code/thimma/mymodule/Controller/Salesorder/Export.php(78): thimma\mymodule\Model\Salesorder->getAllTransactionaldata() #1 /var/www/html/thimmajan3/thimma/vendor/magento/framework/App/Action/Action.php(108): thimma\mymodule\Controller\Salesorder\Export->execute() #2 /var/www/html/thimmajan3/thimma/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http)) #3 /var/www/html/thimmajan3/thimma/vendor/magento/framework/Interception/Interceptor.php(138): thimma\mymodule\Controller\Salesorder\Export\Interceptor->___callParent('dispatch', Array) #4 /var/www/html/thimmajan3/thimma/vendor/magento/module-customer-segment/Model/App/Action/ContextPlugin.php(81): Butt in /var/www/html/thimmajan3/thimma/app/code/thimma/mymodule/Model/Salesorder.php on line 28
1

2 Answers 2

1

Try this one "addFieldtofilter" Change date and column as per requirement

add this code also

protected $date;
public function __construct(
   ....
   \Magento\Framework\Stdlib\DateTime\DateTime $date,
   ....
) {
   ....
   $this->date = $date;
   ....
}
Then get value here of the undefined variable
$now = $this->date->gmtDate()->format('Y-m-d');
$fromDate = date('Y-m-d H:i:s', strtotime('-1 hour'));
$toDate = date('Y-m-d H:i:s', strtotime($now));
$things->addFieldToFilter('created_time', array(
   'from' => $fromDate,
   'to' => $toDate,
   'date' => true,
));
5
  • I'm getting error for this line, $toDate = date('Y-m-d H:i:s', strtotime(now()));
    – MagentoDev
    Commented Apr 13, 2020 at 12:22
  • Uncaught Error: Call to undefined function
    – MagentoDev
    Commented Apr 13, 2020 at 12:23
  • Please post whole error msg , it'll be helpful to solve error. Commented Apr 13, 2020 at 12:26
  • Please check the error, I have posted it on question section
    – MagentoDev
    Commented Apr 13, 2020 at 12:48
  • Answer updated check Commented Apr 13, 2020 at 12:52
0

now() is a mysql function not php you can use it in sql query like this select now();.

Instead you can use date("Y-m-d H:i:s") with php to retrieve current date

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.