Magento 2 Tips : Date Format

Posted About 1 year ago. Visible to the public.
use Magento\Framework\Intl\DateTimeFactory;
=====================================
$endDate = $this->dateTimeFactory
            ->create($milestone->getData('end_date'), new \DateTimeZone('UTC'))->format('d/m/Y');
  ========================================          
            
 $collection = $this->collectionFactory->create();
        $gracePeriod = (int)$this->scopeConfig
            ->getValue(self::XML_PATH_GRACE_PERIOD, ScopeInterface::SCOPE_STORE, null);
        $interval = 'P' . $gracePeriod . 'D';
        $date = $this->dateTimeFactory->create('now', new \DateTimeZone('UTC'));
        $archiveDate = $date->sub(new \DateInterval($interval))->format(DateTime::DATETIME_PHP_FORMAT);

        $collection->addFieldToFilter('status', 1)
            ->addFieldToFilter('updated_at', ['lteq' => $archiveDate]);           
            
            
            $endDate = $this->dateTimeFactory
                    ->create(str_replace('/', '-', $row['start_date']), new \DateTimeZone('UTC'))
                    ->format(DateTime::DATETIME_PHP_FORMAT);
            
            $timestamp = DateTime::createFromFormat('!d/m/Y', '23/05/2023')->getTimestamp();
            =======================================================================
            
            
            
            /** @var \Magento\Sales\Model\Order $order */
        $order = $this->orderRepository->get(37);
        $orderDate = $order->getCreatedAt();
        $convertedOrderDate = $this->dateTimeFactory
            ->create($orderDate, new \DateTimeZone('UTC'))->format('Y-m-d H:i:s');
        $dueDate = $this->dateTimeFactory
            ->create($orderDate, new \DateTimeZone('UTC'))->add(new \DateInterval('P2D'))->format('Y-m-d H:i:s');
        return ['createdDate' => $orderDate, 'convertedDate' => $convertedOrderDate, 'dueDate' => $dueDate];
vasan
Last edit
10 months ago
vasan
Posted by vasan to vasan's deck (2023-03-09 03:58)