MySQL Date Format in Create Table

北战南征 提交于 2021-01-28 02:43:26

问题


I have to create a table with MySql which can store date in the following format : I tried smth like :

CREATE TABLE birth (
....
    date      DATE,
......

);

But it doesn't work since DATE format is YYYY/MM/DD... How can I do ?

Thanks ;)


回答1:


Dates do not have a "format" in MySQL (or in almost any other database). They are stored in some internal format, that is eventually presented to the user.

If you want the date in a particular format, use dateformat() for output. In your case, dateformat(datecol, '%Y/%m/%d').

For input, use the ISO standard format (YYYY-MM-DD) or str_to_date() with the same formatting conventions.



来源:https://stackoverflow.com/questions/29184398/mysql-date-format-in-create-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!