55
votes
Accepted
Magento 2 Get Current Store Date Time
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(
....
...
- 197k
24
votes
Magento 2 Get Current Store Date Time
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 ...
- 13.7k
21
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-...
- 1,076
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:...
- 31.5k
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 ...
- 1,881
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" ...
- 2,148
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 = $...
- 6,246
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 = ...
- 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(...
- 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"
...
- 3,086
8
votes
Accepted
Admin form save date format, month and day wrong way around
Found the problem, was missing a step in my controller.
$postData = $this->getRequest()->getPost();
$postData = $this->_filterDates($postData, array("date"));
After using _filterDates it ...
- 682
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\...
- 508
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 = (...
- 15.5k
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\...
- 3,344
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:...
- 577
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' => __('...
- 111
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 "...
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);
...
- 32.3k
6
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)
...
- 964
5
votes
Accepted
Control Attribute with a date Attribute
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::...
- 13.8k
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\...
- 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/...
- 1,129
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
&...
- 31.5k
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
...
){
...
$...
- 17.1k
4
votes
Magento Adminhtml date picker on custom page (non-form)
$element should belong to Varien_Data_Form, so correct code is:
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/...
4
votes
Accepted
Magento Calender with onSelect event
It seems you are mixing up Magento 1.x and Magento 2.
The code you posted is for Magento 1.x:
Calendar.setup({
inputField : 'store_date',
ifFormat : '%m/%e/%y',
button : '...
- 1,071
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 ->...
- 3,838
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
- 392
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;
}
...
- 17.8k
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 ...
- 121
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
date × 231magento2 × 77
magento-1.9 × 48
php × 14
datepicker × 14
timezone × 13
magento-1 × 12
magento-1.7 × 11
magento-1.8 × 11
filter × 11
format × 11
product × 10
admin × 10
orders × 10
database × 9
grid × 9
calendar × 9
uicomponent × 8
magento-2.1 × 7
attributes × 7
collection × 7
adminhtml × 6
adminform × 6
localisation × 6
special-price × 6