Magento 订单创建日期错误

标签 magento date orders

我正在尝试获取 magento 中从特定用户输入日期起的所有订单。

$orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('created_at', array('from' => $userdate));

但它没有拉出正确的订单。如果我使用今天的日期,它会从昨天提取一半订单,从今天提取一半订单。

经过一番谷歌搜索后,看起来 Magento 中存储了两个日期

$order->getCreatedAt()

似乎给出了 UTC/GMT 时间

$order->getCreatedAtStoreDate()

给出的时间与我在前端看到的时间相同(即我的本地时区)。

如果我发现的内容是正确的,那么如何使用 CreatedAtStoreDate 添加属性到过滤器。我已经尝试过了

('created_at_store_date', array('from' => $userdate)

最佳答案

<?php

ini_set('display_errors',true);
include 'app/Mage.php';
Mage::getIsDeveloperMode(true);
Mage::app();

$formatStr = 'Y-m-d H:i:s';
$startStr  = 'Yesterday 12:00:00AM';
$endStr    = 'Yesterday 11:59:59PM';

$date   = Mage::getSingleton('core/date');
/* @var $date Mage_Core_Model_Date */

$collection = Mage::getResourceModel('sales/order_collection');

$collection->getSelect()
            ->where(
                sprintf("created_at BETWEEN '%s' AND '%s'",
                    $date->gmtDate($formatStr,$startStr),
                    $date->gmtDate($formatStr,$endStr)
                )
            );

$collection->load(true);

关于Magento 订单创建日期错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12812203/

相关文章:

php - 在 PHP 中将一种日期格式转换为另一种日期格式

nopcommerce - nopcommerce 中的取消客户订单功能

php - Woocommerce 3 中可编辑的管理员自定义账单字段错误问题

mysql - 恢复 woocommerce 订单

php - Magento 添加到购物车/客户登录在复制到新域后隐藏

php - Magento 2:通过脚本发送订单确认电子邮件

SQL 日期范围查询 - 表比较

php - 如何修复这个错误?第 X 行出现 fatal error : Call to undefined function ctype_alnum() in . ../magento18/lib/Zend/Uri.php?

mysql - Magento SQL - 将所有产品名称复制到short_description属性

java - SimpleDateFormat 类中可用的日期格式有哪些?