Specific Date Format in mysql

前端 未结 3 1269
醉酒成梦
醉酒成梦 2020-12-04 02:44

Using MySQL

Table

ID Date

001 2010-05-01
002 2010-06-08

Query

Select ID, Date from table;

I want

相关标签:
3条回答
  • 2020-12-04 02:57

    use DATE_FORMAT() in mysql

    look at the link for all format option:

    http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

    0 讨论(0)
  • 2020-12-04 03:11

    Like this:

    SELECT ID, DATE_FORMAT(`Date`, '%d-%M-%Y') FROM table;
    

    You can find other date formatting options for MySQL here: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

    0 讨论(0)
  • 2020-12-04 03:13

    You can use DATE_FORMAT with the format string '%d-%M-%Y'.

    CREATE TABLE table1(ID varchar(100), Date datetime);
    INSERT INTO table1 VALUES
    ('001', '2010-05-01'),
    ('002', '2010-06-08');
    
    SELECT ID, DATE_FORMAT(Date, '%d-%M-%Y') FROM table1;
    

    Result:

    ID    Date
    001   01-May-2010
    002   08-June-2010
    
    0 讨论(0)
提交回复
热议问题