MySQL date formats - difficulty Inserting a date

后端 未结 5 1464
名媛妹妹
名媛妹妹 2020-12-23 19:39

I am trying to further a question I asked yesterday where I wanted to know how to query a date in a different format. But now I am trying to do an insert using this method (

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 20:20

    Put the date in single quotes and move the parenthesis (after the 'yes') to the end:

    INSERT INTO custorder 
      VALUES ('Kevin', 'yes' , STR_TO_DATE('1-01-2012', '%d-%m-%Y') ) ;
                            ^                                     ^
    ---parenthesis removed--|                and added here ------|
    

    But you can always use dates without STR_TO_DATE() function, just use the (Y-m-d) '20120101' or '2012-01-01' format. Check the MySQL docs: Date and Time Literals

    INSERT INTO custorder 
      VALUES ('Kevin', 'yes', '2012-01-01') ;
    

提交回复
热议问题