How to get custom collection before start 1 hour and before end 24 hours Magento 2.
I am not able to add the correct date condition. Does anyone help me, please?
$now = date('Y-m-d H:i:s');
$oneHourBack = date('Y-m-d H:i:s', strtotime('-1 hours', strtotime($now)));
$oneDayBack = date('Y-m-d H:i:s', strtotime('-24 hours', strtotime($now)));
$customCollection = $this->CustomFactory->create()
->getCollection()
->addFieldToFilter('is_membership', 0);
if ($dbColumn == 'MEMBERSHIP_BEFORE_START_1_HOUR') {
$customCollection->addFieldToFilter('pan_start_date', ['neq' => 'NULL']);
$customCollection->addFieldToFilter('pan_start_date', ['lteq' => $oneHourBack]);
} elseif ($dbColumn == 'MEMBERSHIP_BEFORE_END_24_HOUR') {
$customCollection->addFieldToFilter('pan_end_date', ['neq' => 'NULL']);
$customCollection->addFieldToFilter('pan_end_date', ['lteq' => $oneDayBack]);
}
echo $customCollection->getSelect();
$this->logger->info($customCollection->getSelect());
Above condition what I wrong please help?