Magento2: Error: Invalid input datetime format of value '25/07/+00201717'

Created on 10 Aug 2017  路  54Comments  路  Source: magento/magento2


Preconditions


  1. Magento version: 2.1.8
  2. PHP version: 7.0.20
  3. MySQL version: 5.6.36
  4. Magento is setup as multi website with 2 websites, 2 stores, and 2 store views.

Steps to reproduce

  1. Login to Magento admin
  2. Open an existing product for edit
  3. Click save

Expected result

  1. Product is saved successfully as no changes are made from the previous state of the product

Actual result

  1. An error Invalid input datetime format of value '25/07/+00201717' appears and the product is not saved

This issue happened when I upgrade from 2.1.7 to 2.1.8. Some products seems to be able to save without an issue but majority of the ones I tried has this error with various values for the actual date.

Fixed in 2.2.x Fixed in 2.3.x Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.1.x bug report

Most helpful comment

Hello I found a solution online and This is how you fix it

/hosting root/your sitre/vendor/magento/framework/Stdlib/DateTime/Timezone.php
older version magento/magento2/blob/2.3.2/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php#L332-L332
in some cases
Invalid input datetime format of value '3/01/2019'
find this code

  1. $date .= " 0:00am";
    and replace it
    with the following one:
    $date .= ' 00:00';

l hope that helps

All 54 comments

Further investigation shows that the issue is caused by 3 specific dates:

  • Special price date range
  • Schedule design update
  • Set product as new from

These three date forms got populated after the update. They were not under 2.1.7.

When these fields are emptied the product save is successful.

So I was able to figure out why this happens.

The moment.js library returns invalid date format if the account locale is set to "en_GB". If this is the case then moment.js returns ""DD/MM/YYYYYYYY" as format for the date.

A workaround for this issue is to change your account locale to something else like English / United States.

Maybe @magento-team should consider updating the library to 2.18.1

Cannot save product, this issue started after updating to magento 2.1.8. Huge bug as it does not allow product modification. Not sure what else it does but so far have noticed product has issue.

@denchev Changed to locale from magento admin from english australia to english US, still could not save the product. Pretty sad that each release come with such massive issues.
Would be great if someone could provide a solution. I am sure many would not have tried to save the product in magento 2.1.8. Not sure how to now save the product. Update attribute can be saved

@s00071609 I am sorry to hear that you also have this issue. Did you change your account's locale or did you change the store's locale? Account locale is the one that did the trick for me.

@denchev I changed from store>configuration. Where is the account locale?

@denchev I found it - account locale. And it works. I hope it does not cause any other issue. Great solution. Thank you

@s00071609 Glad it worked out for you as well. Two people experiencing this issue is an indication that it is a problem that needs to be looked after.

We are experiencing similar problems with price rules in Magento 2.1.8. After switching the locale to de_DE (with and without german language pack) the validation of a selected from or to date fails. The only difference to 2.1.7 we noticed is the date format the Datepicker returns for validation. en_US works fine as workaround but is no real option for us.

Hello, @denchev. According to Your issue an internal ticket has been created - MAGETWO-71936. You'll be informed as the bug is fixed. Thanks for reporting.

i have also the same issue, when comes a new update of magento?

@denchev thank you for your bug report.
We've created internal ticket MAGETWO-75375 to track progress on the issue.

Same problem here.

The same problem in it-IT

Updated to magento 2.2.0 and continues the problem when saving the product Invalid input datetime format of value, also in the rule this message Something went wrong when saving the data of the rule. Please review the error log.
This problem is when my profile is in language es_ES

Maybe this issue is Related with issue #10580 cc @orlangur

@okorshenko can you assign to me?

Any solution?
Or will I have to keep the EN-EN language forever?

I maked this module to fix, while this error not fixed.

https://github.com/fernandofauth/magento2_datetime

@fernandofauth thanks for the module same issue persists for me however but without the + in the error. The actual error is: Failed to parse time string (18/10/2017) at position 0 (1): Unexpected character.

I resigned,
I will keep the backend in English

In my case problem was yet another one. On Centos with outdated lib-icu 50.1.2 PHP component IntlDateFormatter was giving 'dd.MM.yyyy' pattern instead 'dd.MM.y' which I receive with

$format = (new \IntlDateFormatter(
        'pl_PL', \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE
        ))->getPattern();

echo $format;`

on my local Ubuntu PHP instance supported by ICU 55.1. Seems that relying on IntlDateFormatter pattern output is a pretty serious architectural issue.

Sample fix for pl_PL language https://github.com/lcbrq/magento2-LCB-DateFormatPatch
Feel free to fork and PR extending with other languages because I don't that @magento-engcom-team patch would really close all issues like #10756

@TomashKhamlai are there any wrappers on top of \Intl* in Symfony or somewhere else to make it universal?

IntlDateFormatter is a native PHP component http://php.net/manual/en/class.intldateformatter.php
I don't see it anywhere in vendor/symfony folder.

Hm, ok, https://symfony.com/doc/current/components/intl.html also suggesting using ICU directly.

Hi guys.
I updated the module to magento 2.2.1 and instructions.
https://github.com/fernandofauth/magento2_datetime

I know this is a bad fix, but works for me till the issue with the 'invalid date format when saving a product' is resolved

in /vendor/magento/framework/Stdlib/DateTime/Filter/DateTime.php
inside the filter function
just before $dateTime = new \DateTime($value); in filter() function
add

```
$currentFormat = $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::SHORT);
if($currentFormat=='d/M/yy h:mm a'){
$currentFormat = str_replace('yy','Y',$currentFormat);
$dateParts = explode('/',$value);

            $tmp = explode(' ',$dateParts[2]);
            $tmp[0] = substr($tmp[0], -2);
            $value = $dateParts[1].'/'.$dateParts[0].'/'.$tmp[0];
        }

Then in vendor/magento/module-ui/view/base/web/js/lib/knockout/bindings/datepicker.js
line 52
replace 
 ```
observable() && $(el).datepicker(
                    'setDate',
                    moment(observable(), utils.normalizeDate(config.options.dateFormat)).toDate()

                );

with

if(config.options.dateFormat=='d/M/yy'){

                observable() && $(el).datepicker(
                    'setDate',
                    moment(observable(), utils.normalizeDate('D/M/yyyy')).toDate()

                );
            }
            else{
                observable() && $(el).datepicker(
                    'setDate',
                    moment(observable(), utils.normalizeDate(config.options.dateFormat)).toDate()

                );
            }

hope it helps someone

I made a module which fixed problem for me
This is mix with @fernandofauth and @kksilas solutions

Module on GitHub

@mmularski are you interested in preparing a PR maybe?

@mmularski I tried to use your module, but for my case, it doesn't solve a problem.
I'm using En_UK "Interface Locale" and when I'm trying to save a product "as new" the error is appearing.

@ysapiga I was testing it on en_GB and en_US on Magento 2.1.8 and it works. Could you write error msg from the exception?

edit: I checked adding new product too. Everything works fine for me

Hi @mmularski and @fernandofauth ,

I've tried and the problem remains when I try to edit/create a product.
I'm on Magento 2.1.10 with pt_BR as interface locale.

Hi, I noticed another problem, when the locale is setted to any language where date format is "d/M/yy", all the calendar widgets get this configuration, and then this error occurs, but in filter forms, the date fields still in the "M/d/yy" format. Which is not compatible with the locale configurations.

Another problem detected (so many bugs with dates and i18n). In Marketing -> Catalog Rules, with date format = "dd/M/yy", the core of the magento is again changing the month by day, and displays the following error message: "Something went wrong while saving the rule data. Please review the error log.".

The log is:

[2017-12-11 18:59:18] main.CRITICAL: DateTime::__construct(): Failed to parse time string (31/12/2017) at position 0 (3): Unexpected character {"exception":"[object] (Exception(code: 0): DateTime::__construct(): Failed to parse time string (31/12/2017) at position 0 (3): Unexpected character at /opt/lampp/htdocs/magento_gs/vendor/magento/module-rule/Model/AbstractModel.php:400)"} [] [2017-12-11 19:07:34] main.CRITICAL: DateTime::__construct(): Failed to parse time string (29/11/2017) at position 0 (2): Unexpected character {"exception":"[object] (Exception(code: 0): DateTime::__construct(): Failed to parse time string (29/11/2017) at position 0 (2): Unexpected character at /opt/lampp/htdocs/magento_gs/vendor/magento/module-rule/Model/AbstractModel.php:399)"} [] [2017-12-11 19:08:05] main.CRITICAL: DateTime::__construct(): Failed to parse time string (29/11/2017) at position 0 (2): Unexpected character {"exception":"[object] (Exception(code: 0): DateTime::__construct(): Failed to parse time string (29/11/2017) at position 0 (2): Unexpected character at /opt/lampp/htdocs/magento_gs/vendor/magento/module-rule/Model/AbstractModel.php:399)"} [] [2017-12-11 19:22:18] main.CRITICAL: DateTime::__construct(): Failed to parse time string (31/12/2017) at position 0 (3): Unexpected character {"exception":"[object] (Exception(code: 0): DateTime::__construct(): Failed to parse time string (31/12/2017) at position 0 (3): Unexpected character at /opt/lampp/htdocs/magento_gs/vendor/magento/module-rule/Model/AbstractModel.php:399)"} [] [2017-12-11 19:51:21] main.CRITICAL: DateTime::__construct(): Failed to parse time string (30/11/2017) at position 0 (3): Unexpected character {"exception":"[object] (Exception(code: 0): DateTime::__construct(): Failed to parse time string (30/11/2017) at position 0 (3): Unexpected character at /opt/lampp/htdocs/magento_gs/vendor/magento/module-rule/Model/AbstractModel.php:399)"} [] [2017-12-11 19:55:32] main.CRITICAL: DateTime::__construct(): Failed to parse time string (31/12/2017) at position 0 (3): Unexpected character {"exception":"[object] (Exception(code: 0): DateTime::__construct(): Failed to parse time string (31/12/2017) at position 0 (3): Unexpected character at /opt/lampp/htdocs/magento_gs/vendor/magento/module-rule/Model/AbstractModel.php:400)"} []

@luizpaulofranz , if you have another issue create new report, thank.

Hi @denchev. Thank you for your report.
The issue has been fixed in magento/magento2#11306 by @raumatbel in 2.3-develop branch
Related commit(s):

  • b237558168488b77309d69872bf2d517aa942d49

The fix will be available with the upcoming 2.3.0 release.

Not fixed in 2.2.3. :(

Fix for the issue is currently targeting release 2.2.4

So nothing to go in sale until you release 2.2.4. Is there a file file for this that can be implemented now?

@sopedro this patch seems to have worked for me https://packagist.org/packages/lcbrq/magento2-dateformatpatch

Hi!

I tested @mmularski module on Magento 2.2.4, php 7.1.15, with locale en_GB and it doesn't work.

Any idea?

Regards,
JOINSO

I'm getting the same issue on 2.2.4 - I have tried switching from 'en_gb' to 'en_us' without success :(

capture

I'm getting the same issue on magento 2.2.4 when I switch to Portuguese language in Admin account...

Also still seeing this issue in 2.2.4 when creating promotion cart rules using GB user and site settings.

[2018-06-27 14:18:35] main.CRITICAL: Invalid input date format '27/06/+00201818' {"exception":"[object] (Exception(code: 0): Invalid input date format '27/06/+00201818' at /###/vendor/magento/framework/Stdlib/DateTime/Filter/Date.php:69)"} []

Has this been corrected in 2.2.5?

Hi

This issue seems to be fixed in 2.2.5. Please use the following commit as a reference: 010a6469ea252e865f6f50fd769ff6abeb9376be

More commits may be found with this search: https://github.com/magento/magento2/search?q=MAGETWO-71936&unscoped_q=MAGETWO-71936&type=Commits

Thank you

https://github.com/fernandofauth/magento2_datetime fix works for me i'm in 2.2.4 fr_FR thank's

Issue still present in 2.2.6 running en_gb locale. php 7.1.18.

Issue presents itself when creating product with special price to and from date (Exception(code: 0): Invalid input date format '23/10/+00201818'). Promotion rules the same issue.

We implemented a fix to store date format for special price (product level) using the below recommended by another dev:
/vendor/magento/module-catalog/Controller/Adminhtml/Product/Initialization/Helper.php
has been added a new function on line 463

private function convertSpecialFromDateStringToObject($productData)
{
if (isset($productData['special_from_date']) && $productData['special_from_date'] != '') {
$productData['special_from_date'] = new \DateTime($productData['special_from_date']);
}

    return $productData;
}

comment the call to that function on line 162
//$productData = $this->convertSpecialFromDateStringToObject($productData);

This has fixed the issue for the product level but promo dates are still affected; they save after the above fix but the dates are being overridden with go today date so renders the promotional rule useless.

I can see multiple threads, all which appear related to incorrect date format when using a non US locale and some suggest just switching the store locale to en_US to fix which seems impractical when our users are GB based. Has anyone in GB switched to local en_US with no store impact as we need to find a quick fix so we can prep our black friday deals?

Anyone else on 2.2.6 with the same issue and a fix which is sitewide rather than just product level which we can use until this is patched / addressed thoroughly?

Issue still present in 2.2.6 running en_gb locale for "Special From Date", but is correct for "Special To Date"

Please reopen this issue

I am having this same issue on Magento 2.3. Has anyone found a solution for this?

I am having this same issue on Magento 2.3.1 !

@EmilyPepperman did you by chance find a solution? I've upgraded to 2.3.1 and am also experiencing the date format issue

I am also having this issue after upgrading to 2.3.1 . I can not save modifications on special prices, as I get "Invalid input datetime format of value '5/08/2019'" error.

Hello I found a solution online and This is how you fix it

/hosting root/your sitre/vendor/magento/framework/Stdlib/DateTime/Timezone.php
older version magento/magento2/blob/2.3.2/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php#L332-L332
in some cases
Invalid input datetime format of value '3/01/2019'
find this code

  1. $date .= " 0:00am";
    and replace it
    with the following one:
    $date .= ' 00:00';

l hope that helps

Was this page helpful?
0 / 5 - 0 ratings