Hot answers tagged

53

You need to inject in your class constructor an instance of \Magento\Framework\Stdlib\DateTime\DateTime and use that one. Something like this: protected $date; public function __construct( .... \Magento\Framework\Stdlib\DateTime\DateTime $date, .... ) { .... $this->date = $date; .... } Then, you can use in your class this: $...


24

To get UTC date in Magento2 you should use \Magento\Framework\Stdlib\DateTime\DateTime::gmtDate(); You should inject dependency on this class via construct and then use this function. See this class for more date/time related methods. In your code sample you are retrieving UTC date, not store date. To get date formatted according to the timezone of the ...


17

protected $_date; public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $date) { $this->_date = $date; } then use like this $this->_date->date()->format('Y-m-d H:i:s');


16

If you add the following in your system.xml <frontend_type>text</frontend_type> <frontend_model>namespace_module/adminhtml_system_config_date</frontend_model> Then create the following file: app/code/[codePool]/Namespace/Module/Block/Adminhtml/System/Config/Date.php class Namespace_Module_Block_Adminhtml_System_Config_Date extends ...


16

There is a simple way to achieve that: app/code/Vendor/Checkout/etc/adminhtml/system.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <system> <tab id="mycustom" translate="label" sortOrder="450">...


15

Following is the XML configuration that should work as you intended: <filterRange name="created_at" class="Magento\Backend\Block\Widget\Grid\Column\Filter\Date"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="templates" xsi:type="array"> <item name="...


13

You can easily get Current Store Date Time by injecting in your class constructor in instance of \Magento\Framework\Stdlib\DateTime\TimezoneInterface and use that one to get the DateObject. For example: protected $timezone; public function __construct( .... \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone, .... ) { .... $...


12

You can use this in phtml file : $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $objDate = $objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime'); $date = $objDate->gmtDate(); But using directly object manager in phtml file is not a good practice.


11

In OOP style: $date = new Zend_Date(Mage::getModel('core/date')->timestamp()); $date->addDay('7'); $date->toString('YYYY-MM-dd HH:mm:ss'); //Returns representation of date


11

To add to @Ashvin answer.. I got entries created within the past hour $things = Mage::getModel('things/things')->getCollection(); $things->addFieldToFilter('things_type', 'view'); $fromDate = date('Y-m-d H:i:s', strtotime('-1 hour')); $toDate = date('Y-m-d H:i:s', strtotime(now())); $things->addFieldToFilter('created_time', array( 'from' => ...


9

I'm not sure about your actual use case, but to filter a product collection so that it only returns products created within the last 3 days do as follows $collection = Mage::getResourceModel('catalog/product_collection') ->addFieldToFilter('created_at', array('gt' => date("Y-m-d H:i:s", strtotime('-3 day'))));


9

Here I got the solution: <div class="control customer-dob"> <input type="text" class="input-text required-entry hasDatepicker" id="calendar_inputField" name="dob" aria-required="true" /> <script> require([ "jquery", "mage/calendar" ], function ($)...


8

The problem is in Mage_Eav_Model_Entity_Attribute_Backend_Time_Created::beforeSave. This line ends up swapping the month and day: $zendDate = Mage::app()->getLocale()->utcDate(null, $date, true, $this->_getFormat($date)); This happens to just about all entity types including products and customers, and happens during creation and normal save ...


8

Found the problem, was missing a step in my controller. $postData = $this->getRequest()->getPost(); $postData = $this->_filterDates($postData, array("date")); After using _filterDates it started saving correctly


8

Keep in mi mind that PDO is aware of the timezone set in your Magento installation, which is most likely causing you troubles. When you try to work with automatic timestamps, try using Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s').


7

created_at and updated_at for orders is set in Mage_Sales_Model_Resource_Abstract::_prepareDataForSave(): /** * Prepare data for save * * @param Mage_Core_Model_Abstract $object * @return array */ protected function _prepareDataForSave(Mage_Core_Model_Abstract $object) { $currentTime = Varien_Date::now(); if ((!$object->getId() || $object-&...


7

In Magento2 - Replaced Zend_Date with native PHP DateTime object/functions. So you can use PHP DateTime function in Magento-2 You can get current date by below code. For Example. $currentDate = (new \DateTime()); echo $currentDate->format('Y-m-d'); You can get more help from : http://php.net/manual/en/ref.datetime.php


6

I've just fixed an issue after this exact error happened to me. Not sure if it was an upgrade or not. Regardless, it was because a big chunk of customers had customer_entity set to 0000-00-00 00:00:00 - which Magento really had trouble parsing. Nevertheless, I ran the following SQL query and it fixed it: (Obviously back it up) UPDATE `customer_entity` ...


6

For correct date's output use date_format property $fieldset->addField( 'birthdate', 'date', [ 'name' => 'birthdate', 'label' => __('Birthdate'), 'title' => __('Birthdate'), 'required' => true, 'class' => '', 'singleClick'=> true, ...


6

Yes, Fedex returns delivery date but you have to configure the request sent to the api accordingly. I am not sure your version of magento, This will work in Magento 1.9.x. Rewrite "Mage_Usa_Model_Shipping_Carrier_Fedex" method "_formRateRequest" add 'ReturnTransitAndCommit'=>true to the "ratesRequest" array, ... $ratesRequest = array( '...


6

Mage_Core_Helper_Data::format() it will format the date according to the locale settings. Mage::helper('core')->formatDate($date->date('d F Y', $post->getCreatedTime()), 'medium', false); reference for understanding the date better


5

You have options in product editing to set Set Product as New to Date Set Product as New from Date and in your block you just need to filter the items by those attributes and decide if you display or not.


5

Take a look at calculateSpecialPrice() in /app/code/core/Mage/Catalog/Model/Product/Type/Price.php $dateFrom = $_product->getData('start...'); $dateTo = $_product->getData('end...'); if (Mage::app()->getLocale()->isStoreDateInInterval($store, $dateFrom, $dateTo)) { echo $_product->getData('customattribute'); }


5

Answering my own question now that I solved it. I was missing a date filter to convert the localized date to an internal date before saving my model. I found this when looking at Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog\Save which also does this. In my controller which saves the provided values to my model (I'm omitting a lot of other stuff ...


5

How do we solve it? simple. limiting the amount of orders presented in the orders grid for the last 24 hours, unless requested otherwise. Example:- Copy the app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php file to: app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php Edit the following function, copy-paste from here: protected function ...


5

Simplest Solution: Although, this is likely violating coding standards... echo \Magento\Framework\App\ObjectManager::getInstance() ->create(\Magento\Framework\Intl\DateTimeFactory::class) ->create($post->getCreatedAt(), new \DateTimeZone('America/New_York')) // Update timezone, for example use from config ->format('d F')...


4

$element should belong to Varien_Data_Form, so correct code is: $form = new Varien_Data_Form(array( 'id' => 'edit_form', 'action' => $this->getUrl('*/*/save'), 'method' => 'post' )); $element = new Varien_Data_Form_Element_Date( array( 'name' =>...


4

So date fields are added using Varien_Data_Form_Element_Date. What you could do would be to look into this file and check the function getElementHtml this is where the "magic" happens. You should be able to call something like new Varien_Data_Form_Element_Date($config) where $config is the array used on the call to addElement. Note this is untested but "...


4

Try it. Create a coupon (or rule) with the expiration data 'today' and see if it's available. And to answer the question, the expiration date is included in the validity period. So in your case it should be 12/2/2013.


4

Have not done this myself, so this is a guide to get you in the right direction. the calendar used by magento is located here : /js/calendar/calendar.js, and from its header comments, you will find it is done by http://www.dynarch.com/, and the docs is located here : http://www.dynarch.com/jscal You will see there is built in functionality (via a callback) ...


Only top voted, non community-wiki answers of a minimum length are eligible