MySQL date formats - difficulty Inserting a date

后端 未结 5 1463
名媛妹妹
名媛妹妹 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:11

    Looks like you've not encapsulated your string properly. Try this:

    INSERT INTO custorder VALUES ('Kevin','yes'), STR_TO_DATE('1-01-2012', '%d-%m-%Y');
    

    Alternatively, you can do the following but it is not recommended. Make sure that you use STR_TO-DATE it is because when you are developing web applications you have to explicitly convert String to Date which is annoying. Use first One.

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

    I'm not confident that the above SQL is valid, however, and you may want to move the date part into the brackets. If you can provide the exact error you're getting, I might be able to more directly help with the issue.

提交回复
热议问题