Search code examples
mysqldate-formatting

Mysql Wrong Date Format


Hi I am trying to convert dd-mm-yy to yy-mm-dd in mysql but I'm getting wrong date as below :

 query :  select STR_TO_DATE('01-09-2018','%Y-%m-%d')
   result:  2001-09-20

Please help me to solve this issue.


Solution

  • Try below: format string is wrong in your case

    select STR_TO_DATE('01-09-2018','%d-%m-%Y')
    

    Output:

    '2018-09-01'