mysql - 记录开始时间和结束时间,表字段类型用timestamp还是datetime?
巴扎黑
巴扎黑 2017-04-17 15:56:38
0
4
725
  • mysql数据库

  • 时间都是近期的

巴扎黑
巴扎黑

reply all(4)
巴扎黑

Recommend the questioner to read this post, it summarizes it well. Choose the appropriate MySQL date and time type to store your time

刘奇

Search first

The reply here is very detailed

PHPzhong

Advantages of timestamp compared to datetime:

  1. It takes up little space, timestamp occupies 4 bytes, and datetime occupies 8 bytes;

  2. Contains time zone information. If the time zone is modified in the future, the time represented by timestamp will change with the time zone, but datetime will not.

Disadvantages of timestamp:

  1. can only represent the time from 1970 to 2038, and datetime is not subject to this restriction.

Performance comparison cannot be generalized. Although timestamp is a pure number, the calculation is faster, but it is not readable by humans and must be converted by functions. Datetime is a string type and is directly readable by the human eye. Although it is necessary to calculate addition, subtraction, multiplication and division. After a transformation.

For small applications, there is no need to consider space or performance. The time zone is all Beijing time. Just use datetime directly, and there is no need to worry.

Conclusion: Always use datetime to represent time, never use timestamp unless you have a clear reason or you know what you are doing.

小葫芦

Both types store time. As for the difference in memory usage and efficiency, I won’t talk about it here. In general applications, this difference has no essential impact on your system, so my point of view is business-oriented.
Compared with datetime and timestamp, a timestamp type field will automatically update the value of this field when the database record changes (update), while datetime needs to be manually set before it changes.
Just know this difference when filtering from a business perspective. Generally, choose datetime for create time and timestamp for update time

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!