当前位置: 动力学知识库 > 问答 > 编程问答 >

how to change date format of mysql table column

问题描述:

I have created table called event and it has column birthday which is using the date format of

%Y-%m-%d but I want it to be %d-%m-%Y. so, how can i update it?

when i enter new row with the format %d-%m-%Y it converts it to 0000-00-00 (%Y-%m-%d)

I tried following Queries to change format but it isn't working.

SELECT DATE_FORMAT(CURDATE(), '%d/%m/%Y')

SELECT DATE_FORMAT(column_name, '%d/%m/%Y') FROM tablename

After executing this query it says rows affected and making all the values 0000-00-00.

网友答案:

Try this :

SELECT DATE_FORMAT(dateColumn,'%d/%m/%Y') AS dateColumn FROM table
网友答案:

This should work. I tried and works for me.

select DATE_FORMAT(birthday , '%d/%m/%Y') from event;

But what data type you have for birthday?

See this example.

网友答案:

If you want to insert (or update) a date which isn't in the right format u can use

INSERT INTO `event` (columname) VALUES (STR_TO_DATE('30/09/2014', '%d/%m/%Y'))
分享给朋友:
您可能感兴趣的文章:
随机阅读: