简体   繁体   中英

How does MySQL store timestamps internally?

How does MySQL store timestamps internally? Is it an int, or a string or something else?

From the MySQL Documentation :

TIMESTAMP: A four-byte integer representing seconds UTC since the epoch ('1970-01-01 00:00:00' UTC)

我相信它使用UNIX时间戳,这是一个整数,表示自UNIX纪元以来的秒数:1970年1月1日

All Date, Time, Datetime, Timestamp are stored as Integers internally but Different Datatypes has Different Integers Values Like

YEAR : A one-byte integer

DATE : A three-byte integer packed as YYYY×16×32 + MM×32 + DD

TIME : A three-byte integer packed as DD×24×3600 + HH×3600 + MM×60 + SS

TIMESTAMP : A four-byte integer representing seconds UTC since the epoch ('1970-01-01 00:00:00' UTC)

DATETIME : Eight bytes: A four-byte integer for date packed as YYYY×10000 + MM×100 + DD and a four-byte integer for time packed as HH×10000 + MM×100 + SS

Reference: Data Time Explanatory MySQL Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM