Magento2: Magento 2.1.1 Invalid input date format 'Invalid date'

Created on 1 Oct 2016  路  18Comments  路  Source: magento/magento2

Preconditions

  1. Magento 2.1.1
  2. php 7.0.8

Steps to reproduce

  1. Create an admin listing by using Ui component
  2. There are date type column
  3. Enable the inlineEdit function for the date type column

Expected result

  1. When row is clicked and the inline editing mode enabled, the date column should be converted to the correct value in date picker UI
  2. Save the row should have no error

Actual result

  1. in editing mode, the date value showed in the Date Picker Ui will always shows the value of current date instead of the actual column value
  2. Randomly error Invalid input date format 'Invalid date' will show up, but if clicking the date picker something else seem to be triggered and then it would be fine to save from inlineEdit mode
Frontend Fixed in 2.1.x Fixed in 2.2.x Fixed in 2.3.x Format is valid Ready for Work bug report

Most helpful comment

Still experiencing in 2.2.3

All 18 comments

I experience this error on Magento ver. 2.1.3 (PHP 7.0.13).

May I add that you don't even need to create your own listing using UI components.
It happens in the core modules also.
Steps to reproduce.

  • Go to Content->CMS->Pages list in the backend.
  • Edit a page (not inline edit - regular edit) and set a value for "Custom design from"
  • go back to the list
  • Make the "Custom Design from" column visible.
  • Inline edit the item that has a value for Custom design from"
  • Hit save without changing anything.

Expected result:

  • the page saves and I get a success message

Actual result:

  • I get an error message [Page ID: 1] Something went wrong while saving the page..

Additional details

  • here is how the post data looks like
items[1][title]=404+Not+Found&   
items[1][identifier]=no-route&  
items[1][page_layout]=2columns-right&  
items[1][is_active]=1&  
items[1][custom_theme_from]=Invalid+date&  
items[1][custom_theme_to]=&  
items[1][custom_theme]=&  
items[1][custom_root_template]=&  
items[1][meta_title]=&  
items[1][meta_keywords]=Page+keywords&  
items[1][meta_description]=Page+description&  
items[1][page_id]=1&  
form_key=(irelevant)

Notice the value for custom_theme_from.

Conclusion:
It works for empty date values and when you change the date in the inline edit, but it does not work when you inline edit something and you don't change a date field value.

I also have same problem while creating new product. While adding new product if 'Set Product as New FROM DATE to TO DATE', 'Schedule update FROM DATE to TO DATE', 'Special Price FROM DATE to TO DATE' any of the field have blank date then i get invalid date error and can not add product.
I am using en_GB locale interface and i tried again n again after changing it to en_US but still error generate.
Magento Version 2.1.5

In 2.1.1 we were able to fix the problem by updating the interface_locale back to en_US for all affected admin users.

UPDATE admin_user SET interface_locale = 'en_US' WHERE interface_locale = 'en_AU';

Clearly not a permanent solution, but better then the error.

The bug is in the static content that Magento create for performace issue:

pubstatic\adminhtml\Magento\backend{locale}\Magento_Ui\js\lib\validation\rules.js

In this file there are more rules about the validation of the date.
Example by considering locale = it_IT
There is a correct rule that check the date on basis of locale format:

"dateITA": [
            function(value) {
                var check = false;
                var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
                if (re.test(value)) {
                    var adata = value.split('/');
                    var gg = parseInt(adata[0], 10);
                    var mm = parseInt(adata[1], 10);
                    var aaaa = parseInt(adata[2], 10);
                    var xdata = new Date(aaaa, mm - 1, gg);
                    if ((xdata.getFullYear() === aaaa) &&
                        (xdata.getMonth() === mm - 1) && (xdata.getDate() === gg )) {
                        check = true;
                    } else {
                        check = false;
                    }
                } else {
                    check = false;
                }
                return check;
            },
            $.mage.__('Please enter a correct date')
        ],

Below there is another rule that checks the date value without considering the locale format:

"validate-date": [
            function(value) {
                            var test = new Date(value);
                           return utils.isEmptyNoTrim(value) || !isNaN(test);
                         },
                       $.mage.__('Please enter a valid date.')
        ],

Replacing the function of the "validate-date" rule with the function of the "dateITA" (if the locale is it_IT) rule, the validation problem is resolved.
But persist the presentation problem, because you can save (in my case) the customer Date of Birthday correctly, but when you open the form again the date of DoB is wrong.
However this is the way to fix the bug definitively.
Tested on Magento 2.1.8 in the admin panel section.

Internal ticket to track issue progress: MAGETWO-80096

Hi @Nerogee the issue has been fixed in https://github.com/magento/magento2/pull/11067 by @joachimVT. The fix will be available in 2.2.1

Not fixed 2.2.1.

magento2-1-1

@digvijay2017 i hope this module help to you and any body.
Module Fix Date

I confirm issue.
@bahramdavodi , great module man, a little bug is in di.xml in type attribute, you have to replace with
<preference for="Magento\Framework\Stdlib\DateTime\Timezone" type="Magonex\DateTime\Framework\Timezone"/>

My version 2.2.1

@gianiaco fixed. thanks

Hi @bahramdavodi

After installing your module, I am not getting the other date format in calendar. Calendar is always showing the US date format, because in your function, you have added 'en_US' hard coded. I think, it's not a proper solution.

  public function getDateFormat($type = \IntlDateFormatter::SHORT)
    {
        return (new \IntlDateFormatter(
        //$this->_localeResolver->getLocale(),
            'en_US',
            $type,
            \IntlDateFormatter::NONE
        ))->getPattern();
    }

@digvijay2017 this problem is with libicu in centos. magento work well in the Ubuntu and Debian or Mac OS well.
i'm support magento for persian language and for now this is best solution.

i'm writting a new module for this problem. when this extension is finished, i published it.

thanks for you

Hi @Nerogee. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1353 by @magento-engcom-team in 2.3-develop branch
Related commit(s):

  • 299109f1265fa15eeb3067e22c2638ff5907205e
  • 57318bf03bf6fe7f84b2956ffb5ecc1332bf41b3
  • 41cd961a217d30c4b7b051a775902c4fb40b84ea
  • 076b90398852478d93d1444f936ac483b4640a82
  • 435a6c200cd548b8765e5bc73b0458039a58645d
  • 5d174b873f8ba369d6504fb9d7ef30296816e2b1
  • a47b10dce854a2d21ead6b362b86ca3ddf595386
  • ab48cb176830ddab69fd1617cae96d76094ab167
  • 46be4c7ea59f6cfb9884f2bc5875245b1960edc6
  • eafc6f0a473547542c3ef80352dcd2be7128da87
  • 63b9e909f1173a51374d4cdfc68249baa66f0007
  • 2edfe9a30bb64f0a7e102bb335a89658b627bfad
  • ef5ddffb43a735627d09535b62fac2a41804a96a
  • 4ada797ece84c2f5eb55499e8bc3f75e0c7ef245
  • c5d9a019b0d51a51b452fd99b527e3b894874be2
  • 72e9e0732b98ea5b8f47bddc781dc47c688c3c58
  • 215180de0a3f6c4a16e02205732bfe8670293ad2
  • 685d50625b68dbb960988a6bfbbfc14455a6cb9e

The fix will be available with the upcoming 2.3.0 release.

Still experiencing in 2.2.3

Also experiencing in 2.2.3, managed to fix it by switching my locale to en_US from en_GB but that's not a fix Magento.

I am getting the same error in magento 2.3.5
Please Check
https://prnt.sc/sjlii0
I already applied Magonex extension for datetime, but it did not work for me.

Was this page helpful?
0 / 5 - 0 ratings