MySQL datetime format to dd/mm/yy 00:00:00

早过忘川 提交于 2021-02-17 03:17:42

问题


How can I alter a Mysql table time stamp to such as the following:

dd/mm/yy 00:00:00

I tried:

ALTER TABLE TbMessage MODIFY startdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;

But is not the formate as i thought:

0000-00-00 00:00:00

can some one help me? Because the date which i am receiving for the table is in the format DD/MM/YYYY from a SQL Database. I cant chnage the formate in the database of SQL.


回答1:


A timestamp/datetime is always stored the same way in the database. It is the representation in your selects that you can influence.

For that you can use DATE_FORMAT. Example:

select date_format(datetime_column, '%d/%m/%Y %k:%i:%s') 
from your_table

And if you want to store date and time you should rather use the datetime data type. So I recommend to use

ALTER TABLE TbMessage 
MODIFY `startdate` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL


来源:https://stackoverflow.com/questions/18965119/mysql-datetime-format-to-dd-mm-yy-000000

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