Error while inserting date - Incorrect date value:

前端 未结 7 1740
花落未央
花落未央 2020-12-09 08:31

I have a column called today and the type is DATE.

When I try to add the date in the format \'07-25-2012\' I get the following

7条回答
  •  春和景丽
    2020-12-09 08:59

    As MySql accepts the date in y-m-d format in date type column, you need to STR_TO_DATE function to convert the date into yyyy-mm-dd format for insertion in following way:

    INSERT INTO table_name(today) 
    VALUES(STR_TO_DATE('07-25-2012','%m-%d-%y'));  
    

    Similary, if you want to select the date in different format other than Mysql format, you should try DATE_FORMAT function

    SELECT DATE_FORMAT(today, '%m-%d-%y') from table_name; 
    

提交回复
热议问题