Home > Database > Mysql Tutorial > body text

datetime data type

(*-*)浩
Release: 2019-07-09 10:07:14
Original
19651 people have browsed it

MySQL date data type datetime.

datetime data type

##datetime type: can be used for values ​​that need to contain both date and time information. (Recommended learning: MySQL video tutorial)

datetime:MySQL retrieves and displays the DATETIME type in the 'YYYY-MM-DD HH:mm:ss' format.

TypeSize (bytes)RangeFormatUseDATETIME 81000-01-01 00:00:00/9999-12 -31 23:59:59YYYY-MM-DD HH:MM:SS Mixed date and time values ​​






When creating a table in MySQL, it is easy to choose the data type that suits you through the type introduction. However, it may be a bit difficult to choose datetime or timestamp. Both date and time types have their own advantages: datetime has a larger date range; timestamp occupies a smaller storage space, only half of datetime.

In addition, timestamp type columns have another feature: by default, when inserting and updating data, the timestamp column will automatically be filled/updated with the current time (CURRENT_TIMESTAMP). "Automatic" means that if you don't care about it, MySQL will handle it for you.

The code to create a table is:

create table t8 (
  `id1` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `id2` datetime default NULL
);
Copy after login
Generally, I tend to use the datetime date type.

Comparison between the two:

1. The range supported by timestamp is smaller than that of timedate. And it is easy to exceed the situation

2.timestamp is more affected by the time zone, the MYSQL version and the SQL MODE of the server.

For more MySQL related technical articles, please visit

MySQL database graphic tutorial column to learn!

The above is the detailed content of datetime data type. For more information, please follow other related articles on the PHP Chinese website!

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!