Hot answers tagged

22 votes

Magento 2: How to get current date, date time with format in .phtml file?

protected $_date; public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $date) { $this->_date = $date; } then use like this $this->_date->date()->format('Y-...
ManiMaran A's user avatar
  • 1,126
18 votes
Accepted

Date field system.xml

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:...
Khoa TruongDinh's user avatar
15 votes

Magento 2 Get Current Store Date Time

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 ...
Mr. Lewis's user avatar
  • 1,921
15 votes

How to change date format of magento 2 admin grid filter without using ui component?

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" ...
bassplayer7's user avatar
  • 2,186
12 votes
Accepted

Magento 2: How to get current date, date time with format in .phtml file?

You can use this in phtml file : $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $objDate = $objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime'); $date = $...
Ashish Jagnani's user avatar
11 votes
Accepted

Magento Filter collection by create times (today, yesterday, week, hour etc)

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 = ...
BENN1TH's user avatar
  • 814
9 votes

Get current date time used in magento for saving data

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(...
Stjepan's user avatar
  • 184
9 votes
Accepted

How do I create date input field with calendar in Magneto2? [SOLVED]

Here I got the solution: <div class="control customer-dob"> <input type="text" class="input-text required-entry hasDatepicker" id="calendar_inputField" ...
Manish's user avatar
  • 3,106
7 votes

Magento 2: How to use Zend Date

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 = (...
Suresh Chikani's user avatar
7 votes

Magento 2 Get Current Store Date Time

Magento 2.x have context objects for different classes, if you are in a context of Block then context object can give you locale date object as follows: /** * Locale Date/Timezone * @var \Magento\...
mshakeel's user avatar
  • 528
7 votes
Accepted

Magento 2.2.3 How to adjust date format?

Simplest Solution: Although, this is likely violating coding standards... echo \Magento\Framework\App\ObjectManager::getInstance() ->create(\Magento\Framework\Intl\DateTimeFactory::class) ...
df2k2's user avatar
  • 984
6 votes

Adminhtml form date input type default format wrong

For correct date's output use date_format property $fieldset->addField( 'birthdate', 'date', [ 'name' => 'birthdate', 'label' => __('...
Magento's God's user avatar
6 votes
Accepted

'No date part in '' found. when upgrading from Magento 1.9.0.x to 1.9.2.2

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:...
Thomas Harding's user avatar
6 votes

Magento 2 Get Current Store Date Time

To get the current date time of a particular store (other than current store in StoreManager): Reference from \Magento\Framework\Stdlib\DateTime\Timezone::convertConfigTimeToUtc() /** @var \Magento\...
Daniel Ifrim's user avatar
  • 3,394
6 votes
Accepted

Translate $date into Dutch

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); ...
Qaisar Satti's user avatar
  • 32.5k
6 votes

How to show fedex estimated delivery date to be displayed along with the shipping option on my checkout page

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 "...
Fekadesilassie Melisew's user avatar
5 votes
Accepted

Problems with DateTime: failed to parse time string

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\...
peedee's user avatar
  • 713
5 votes

Magento Filter collection by create times (today, yesterday, week, hour etc)

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/...
Ashvin Monpara's user avatar
5 votes

Add Custom Product Grid Created Date And Created By Magento 2

We can find the Create At field in table: catalog_product_entity. So, for this field, we only need to show it: For example: app/code/Vendor/Catalog/view/adminhtml/ui_component/product_listing.xml &...
Khoa TruongDinh's user avatar
5 votes

How to get date of tomorrow in magento2

Use this below code to get date of tomorrow : Dependency Method : protected $date; public function __construct( ... \Magento\Framework\Stdlib\DateTime\DateTime $date ... ){ ... $...
Rohan Hapani's user avatar
  • 17.3k
4 votes
Accepted

Magento 2 set created time and updated time in database

protected $_dateFactory; public function __construct( \Magento\Framework\Stdlib\DateTime\DateTimeFactory $dateFactory ) { $this->_dateFactory = $dateFactory; } ...
Keyur Shah's user avatar
4 votes

Get current date time used in magento for saving data

use the following function. It will auto calculate the time according to the timezone saved in admin Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s') Store this data in db
Vivek Khandelwal's user avatar
4 votes

Change date format

Don't forget about locale! As all other examples can cause issues for people from different time zones. Mage::app()->getLocale()->date() inside date() you can put any date and call method ->...
zhartaunik's user avatar
  • 3,848
4 votes

Magento 2 : How to change default date format every where in magento?

To change visible date format in date inputs You need to set proper Interface Locale in the Account Setting. After that You will see changes on the Edit Product Page. To change dates in frontend ...
sbodak's user avatar
  • 121
4 votes

Magento : Catalog Price Rule Date Not Working Properly

I cant comment, you need to check some conditions : 1)cron jobs working or not by installing Aoe scheduler extension or some other way 2)check magento site timings and server timings both are same
raj's user avatar
  • 69
4 votes
Accepted

Magento 2 - Admin grid and export use different timezone

I've found an answer for this problem. Please do comment if there's anything wrong about this answer. Basically we have to add metadataprovider configuration in [ModuleName]/etc/adminhtml/di.xml ...
user7414328's user avatar
3 votes

Magento 2 Get Current Store Date Time

We can set store timezone using observer with event "controller_action_predispatch" Create events.xml in Mymodle/etc/frontend/events.xml folder <?xml version="1.0" encoding="UTF-8"?> <...
Sachin's user avatar
  • 111
3 votes

Magento 2 - Best practice to get current date

That is very simple, since \DateTime object always contains a timezone, it is possible to translate it into UTC at any time, but unfourtunately Magento 2.0 code base does not do. Take a look at this ...
Ivan Chepurnyi's user avatar
3 votes

How to change magento date/time

like what zigojacko told you, it is much easier for you to test it manually, find the cron job that you want to call, for example in your config.xml if you have: <module_email> <schedule>...
Nickool's user avatar
  • 1,069
3 votes

Magento 2.1: Product date validation prevents saving "Make sure the To Date is later than or the same as the From Date."

We were facing the similar issue with multi-store products. We then tried to save the product at default level without any changes, and no error was observed. We then tried the same at different ...
Deepika Janiyani's user avatar

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