how to convert a string to date in mysql?

后端 未结 5 602
谎友^
谎友^ 2020-11-22 07:26

I have a string column which acts as a date and I want to select it as a date.

Is it possible?

My sample data format

5条回答
  •  一个人的身影
    2020-11-22 07:35

    Here's another two examples.

    To output the day, month, and year, you can use:

    select STR_TO_DATE('14/02/2015', '%d/%m/%Y');
    

    Which produces:

    2015-02-14

    To also output the time, you can use:

    select STR_TO_DATE('14/02/2017 23:38:12', '%d/%m/%Y %T');
    

    Which produces:

    2017-02-14 23:38:12

提交回复
热议问题