Home > Database > Mysql Tutorial > body text

Does Mysql use int, timestamp or datetime to store time fields?

高洛峰
Release: 2016-12-02 13:23:19
Original
1446 people have browsed it

Usually the datetime type is used to store time. Now many systems also use int to store time. What is the difference between them? My summary is as follows:

int

(1). 4 bytes of storage. The length of INT is 4 bytes. The storage space is less than datatime. The int index storage space is also relatively small, and the sorting and query efficiency are relatively high. A little higher
(2) The readability is extremely poor and the data cannot be seen intuitively, which may make you very annoyed


TIMESTAMP

(1) 4 bytes storage
(2) The value is saved in UTC format
(3) Time zone conversion, convert the current time zone when storing, and convert back to the current time zone when retrieving.
(4) TIMESTAMP value cannot be earlier than 1970 or later than 2037


datetime

(1) 8 bytes storage
(2) Independent of time zone

(3) Ended with 'YYYY-MM-DD HH Retrieve and display DATETIME values ​​in :MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'

mysql has only become popular in the past two years, and its performance is getting better and better. How to store it depends on the individual. Habits and project needs


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!