MySQL - 日期列格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17163096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL - Date Column Format
提问by Michael 'Maik' Ardan
I am familiar with DATE_FORMAT
function which can display the the record from my date field in the format specified. However, I would like to create a table with a date field that only accepts my format.
Here's what I have done so far:
我熟悉DATE_FORMAT
可以按指定格式显示日期字段中的记录的功能。但是,我想创建一个带有仅接受我的格式的日期字段的表。
这是我到目前为止所做的:
CREATE TABLE test_table (
id INT AUTO_INCREMENT,
f_name VARCHAR(40) NOT NULL,
l_name VARCHAR(25) NOT NULL,
date_hired DATE NOT NULL
);
Inserting a record with a date_hired value of '2013-03-01' will be inserted as '1/03/2013 12:00:00 AM' which is far from my expected result (I would like the format the way it was inserted). Any feedback? Did I miss something?
Thanks,
Michael
插入 date_hired 值为“2013-03-01”的记录将被插入为“1/03/2013 12:00:00 AM”,这与我的预期结果相去甚远(我想要插入的格式)。任何反馈?我错过了什么?
谢谢,
迈克尔
回答by kundan
You can't change the format during table create, you can change the format of date for displaying user by using you programming logic like if you are using PHP as your server side language the you can convert it your desired format.
您无法在表创建期间更改格式,您可以使用编程逻辑更改显示用户的日期格式,就像您使用 PHP 作为服务器端语言一样,您可以将其转换为所需的格式。