Home > Database > Mysql Tutorial > body text

MySQL数据库中的Date,DateTime,TimeStamp和Time类型

WBOY
Release: 2016-06-07 15:18:23
Original
1330 people have browsed it

DATETIME 类型用在你需要同时包含日期和时间信息的时。MySQL检索并且以'YYYY-MM-DD HH:MM:SS'式显示DATETIME,支持的范围是'1000-01-01 00:00:00'到'9999-12-31 23:59:59'。(“支持”意味着尽管更早的可能工作,但不能保证他们可以。) DATE 类型用在你仅需

DATETIME类型用在你需要同时包含日期和时间信息的值时。MySQL检索并且以'YYYY-MM-DD HH:MM:SS'格式显示DATETIME值,支持的范围是'1000-01-01 00:00:00'到'9999-12-31 23:59:59'。(“支持”意味着尽管更早的值可能工作,但不能保证他们可以。)


DATE类型用在你仅需要日期值时,没有时间部分。MySQL检索并且以'YYYY-MM-DD'格式显示DATE值,支持的范围是'1000-01-01'到'9999-12-31'。


TIMESTAMP列类型提供一种类型,你可以使用它自动地用当前的日期和时间标记INSERT或UPDATE的操作。


TIME数据类型表示一天中的时间。MySQL检索并且以"HH:MM:SS"格式显示TIME值。支持的范围是'00:00:00'到'23:59:59'。




创建表SQL


CREATE TABLE `tb_test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date1` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIM
ESTAMP,
  `date2` date DEFAULT NULL,
  `date3` datetime DEFAULT NULL,
  `time` time DEFAULT NULL,
  PRIMARY KEY (`id`)
);
Copy after login


运行效果截图:

MySQL数据库中的Date,DateTime,TimeStamp和Time类型


 
参考资料:
MySQL数据库中的Date,DateTime和TimeStamp类型 


mysql教程:MySQL显示数据库数据


MySQL中的datetime与timestamp比较 



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!