MySQL:最好的使用,Unix TimeStamp或DATETIME [英] MySQL: What's the best to use, Unix TimeStamp Or DATETIME
问题描述
对我来说,我使用Unix时间戳,因为我可以很容易地转换&订单记录与它,也因为我从来没有尝试过DATETIME的事情。但是无论如何,如果有人告诉我我错了,我准备好改变主意。
谢谢
Timestamp (PHP和MySQL的一个)使用32位(即4字节)存储整数;这意味着它们限于从1970年到2038年的日期范围。
DATETIME
没有限制 - 但是使用更多的字节存储(8个字节,如果我没有错误)
之后在PHP看到的存储时间戳之间,或MySQL看到的时间戳记:
- 使用PHP时间戳表示操作从PHP更容易 - 日期/时间功能
- 使用MySQL的时间戳表示操作从MySQL更容易 - 请参阅 11.6。日期和时间函数
另外,MySQL的 TIMESTAMP
和 DATETIME
数据类型,请参阅 10.3.1。 DATETIME,DATE和TIMESTAMP类型
Probably many coders want to ask this question. it is What's the adventages of each one of those MySQL time formats. and which one you will prefer to use it in your apps.
For me i use Unix timestamp because maybe i find it easy to convert & order records with it, and also because i never tried the DATETIME thing. but anyways i'm ready to change my mind if anyone tells me i'm wrong.
Thanks
Timestamp (both PHP ones and MySQL's ones) are stored using 32 bits (i.e. 4 bytes) integers ; which means they are limited to a date range that goes from 1970 to 2038.
DATETIME
don't have that limitation -- but are stored using more bytes (8 bytes, if I'm not mistaken)
After, between storing timestamps as seen by PHP, or timestamps as seen by MySQL :
- using PHP timestamps means manipulations are easier from PHP -- see Date/Time Functions
- using MySQL's timestamps means manipulations are easier from MySQL -- see 11.6. Date and Time Functions
And, for more informations between MySQL's TIMESTAMP
and DATETIME
datatypes, see 10.3.1. The DATETIME, DATE, and TIMESTAMP Types
这篇关于MySQL:最好的使用,Unix TimeStamp或DATETIME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!