简体   繁体   English

php / mysql安装中的unix时间戳 - 最好的MySQL数据类型存储它?

[英]unix timestamp in php/mysql installation - best MySQL datatype to store this as?

I'm trying to figure out the best datatype and size in my DB to store unix timestamps... 我试图找出我的数据库中存储unix时间戳的最佳数据类型和大小...

In otherwords: 换一种说法:

INT(32)

etc... 等等...

Thanks for any tips. 谢谢你的任何提示。

TIMESTAMP is a pretty straight-forward choice. TIMESTAMP是一个非常直接的选择。 It's implemented as a UNIX timestamp internally, but externally it appears as a date string (eg "1970-01-01 00:00:01"). 它在内部实现为UNIX时间戳,但在外部它显示为日期字符串(例如“1970-01-01 00:00:01”)。

EDIT: To migrate an INT to a timestamp, where time_test is the table and ts is the original column: 编辑:将INT迁移到时间戳,其中time_test是表, ts是原始列:

ALTER TABLE time_test ADD ts_new TIMESTAMP;
UPDATE time_test SET ts_new = FROM_UNIXTIME(ts);
ALTER TABLE time_test DROP ts;
ALTER TABLE time_test CHANGE COLUMN ts_new ts TIMESTAMP;

You may have to tweak it slightly if you care about the column order. 如果您关心列顺序,可能需要稍微调整一下。

MySql supports Unix timestamps directly as the TIMESTAMP data type. MySql直接支持Unix时间戳作为TIMESTAMP数据类型。

You have the normal limitations; 你有正常的限制; dates must be from 1 Jan 1970 until 19 Jan 2038. 日期必须是1970年1月1日至2038年1月19日。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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