Home > Database > Mysql Tutorial > body text

mysql 时间类型总结

WBOY
Release: 2016-06-07 15:33:45
Original
1362 people have browsed it

MySQL数据库中关于日期、时间的类型有以下四中:Date,DateTime,TimeStamp和Time 1、DATETIME类型:用在你需要同时包含日期和时间信息的时。MySQL检索并且以'YYYY-MM-DD HH:MM:SS'式显示DATETIME,支持的范围是'1000-01-01 00:00:00'到'9999-12-31 23:59:59'

MySQL数据库中关于日期、时间的类型有以下四中:Date,DateTime,TimeStamp和Time


1、DATETIME类型:用在你需要同时包含日期和时间信息的值时。MySQL检索并且以'YYYY-MM-DD HH:MM:SS'格式显示DATETIME值,支持的范围是'1000-01-01 00:00:00'到'9999-12-31 23:59:59'。

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


3、TIMESTAMP类型提供日期和时间信息,同样以'YYYY-MM-DD HH:MM:SS'格式显示。和datetime类型的区别是保存的时间较小,年的数字在:1970 --2037 之间。你可以使用它自动地用当前的日期和时间标记INSERT或UPDATE的操作(默认更新时自动刷新)。


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

实例:

test表结构:

mysql 时间类型总结

插入数据:

mysql 时间类型总结

查看:

mysql 时间类型总结

更新:

mysql 时间类型总结

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!