MySQL datetime格式为dd/mm/yy 00:00:00 [英] MySQL datetime format to dd/mm/yy 00:00:00

查看:83
本文介绍了MySQL datetime格式为dd/mm/yy 00:00:00的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Mysql表的时间戳更改为以下内容:

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

dd/mm/yy 00:00:00

我尝试过:

ALTER TABLE TbMessage 修改开始日期TIMESTAMP DEFAULTCURRENT_TIMESTAMP NOT NULL;

ALTER TABLE TbMessage MODIFY startdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;

但不是我想的那样:

0000-00-00 00:00:00

有人可以帮助我吗?因为我收到的日期是来自SQL数据库的DD/MM/YYYY格式.我无法在SQL数据库中更改格式.

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.

推荐答案

时间戳/ datetime 始终以相同的方式存储在数据库中.可以影响您选择的表示形式.

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

为此,您可以使用 DATE_FORMAT .示例:

For that you can use DATE_FORMAT. Example:

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

如果要存储 date time ,则应使用 datetime 数据类型.所以我建议使用

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

这篇关于MySQL datetime格式为dd/mm/yy 00:00:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆