Skip to content

How to Fix the wrong input format of Customer date of birth  #11332

@selusi

Description

@selusi

Preconditions

  1. PHP 7.0.22
  2. MySql 5.7
  3. Apache 2.4
  4. Magento 2.2.0

Steps to reproduce

  1. Login to frontend
  2. Edit Customer information

Expected result

  1. The year of birth date should be in the format: yyyy.

Actual result

  1. The actual format is yy

To fix the issue

To solve the issue have to modify the file:
vendor\magento\module-customer\Block\Widget\Dob.php
Actually the line 113 is:

$data['format'] = $this->getDateFormat(); 

(that return MM/dd/yy format in English locale)
This format is good for javascript datepicker configuration but it is wrong for the form input text.
I wrote a method that return the correct date format:

protected function getDateFormatForInput()
{
    $formatArr = explode(' ', preg_replace("/[^a-zA-Z]/",' ',$this->getDateFormat())) ;
    $reseteFormat = array();
    foreach($formatArr as $k){
        if($k != ''){
            if(substr($k,0,1) == 'y' ){
                $reseteFormat[] = 'yyyy';
            } else {
                $reseteFormat[] = $k;
            }
        }
    }
    return implode("/", $reseteFormat);
}

the new 113 line:

$data['format'] = $this->getDateFormatForInput(); 

Obviously this is my code though not very elegant, but it solves the problem.

Metadata

Metadata

Assignees

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions