0

I'm trying to filter the data collection from 4 hours to now and I have the below code but its not working.

public function getWishlistProduct($wishlistid){
$to = date("Y-m-d h:i:s");
$from = strtotime('-4 hours', strtotime($to));
$from = date('Y-m-d h:i:s', $from); 
$wishlist= $this->getCollection()->addFieldToFilter('wishlist_id', ['eq'=>$wishlistid])
 ->addFieldToFilter('added_at', array('from'=>$from, 'to'=>$to));
return $wishlist;
 
}

Could anyone please help?

asked Jun 18, 2020 at 14:16
1
  • Its showing HTTP ERROR 500 Commented Jun 18, 2020 at 16:42

1 Answer 1

0

I have solved this issue by using the time() function and the updated code as below. Hope it may helpful to someone:

public function getWishlistProduct($wishlistid){
 $time = time();
 $to = date('Y-m-d H:i:s', $time);
 $lastTime = $time - 14400; //60*60*4
 $from = date('Y-m-d H:i:s', $lastTime);
 $wishlist= $this->getCollection()->addFieldToFilter('wishlist_id', ['eq'=>$wishlistid])
 ->addFieldToFilter('added_at', array('from'=>$from, 'to'=>$to));
 return $wishlist;
 
 }
answered Jun 18, 2020 at 17:09
2
  • 1
    sound good , Or above my code why showing 500 error because i am missed some column(,) and i am not sure $from = date('Y-m-d H:i:s', strtotime('-4 hour')); $toDate = date('Y-m-d H:i:s',$from); $wishlist= $this->getCollection()->addFieldToFilter('wishlist_id', ['eq'=>$wishlistid]) ->addFieldToFilter('added_at', array('from'=>$from, 'to'=>$toDate,'date'=>true)); return $wishlist; Commented Jun 18, 2020 at 17:18
  • @MohitPatel, Can you please check this magento.stackexchange.com/questions/315373/… and help me out. Commented Jun 19, 2020 at 2:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.