2
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_reviewsColFactory = $objectManager->get("\Magento\Review\Model\ResourceModel\Review\CollectionFactory");
$_storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$reviewsCollection = $_reviewsColFactory->create()
                                        ->addStoreFilter($_storeManager->getStore()->getStoreId())
                                        ->addStatusFilter(\Magento\Review\Model\Review::STATUS_APPROVED)
                                        ->setDateOrder();
<?php foreach($reviewsCollection as $review):?>
<?php echo $review['review_id'];  ?>----<?php echo $review['created_at'];  ?><br/>
<?php endforeach;?>

$review['created_at'] is not getting the value that is present in database.

1
  • Solution: $formatDate = $objectManager->create('\Magento\Framework\Stdlib\DateTime\TimezoneInterface'); Inside loop add code echo $review['review_id']."--".$formatDate->formatDateTime($review['created_at']); After this created_at will be same as in database
    – Danes
    Jul 23, 2019 at 1:12

1 Answer 1

0

There might be an issue in your other code, I have used your code and it is working fine see below code and result.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_reviewsColFactory = $objectManager->get("\Magento\Review\Model\ResourceModel\Review\CollectionFactory");
$_storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$reviewsCollection = $_reviewsColFactory->create()
                                        ->addStoreFilter($_storeManager->getStore()->getStoreId())
                                        ->addStatusFilter(\Magento\Review\Model\Review::STATUS_APPROVED)
                                        ->setDateOrder();
foreach($reviewsCollection as $review):
echo 'Review Id =>', $review['review_id']; echo ' | Review Date =>', $review['created_at']; echo '<br/>'; 
endforeach;

die('called');

And result :

review image

I hope it helps!

5
  • Can you please check with the database table?
    – Danes
    Jul 22, 2019 at 5:48
  • the created_at value displayed through the script above and database table value is different, that is an issue
    – Danes
    Jul 22, 2019 at 5:52
  • this is your issue. Jul 22, 2019 at 6:15
  • yes i know the issue is related to timezone but how would you implement in the above script
    – Danes
    Jul 22, 2019 at 6:22

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.