开发者

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...

In otherwords:

INT(32)

etc...

Thanks for any t开发者_如何转开发ips.


TIMESTAMP is a pretty straight-forward choice. It's implemented as a UNIX timestamp internally, but externally it appears as a date string (e.g. "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:

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.

You have the normal limitations; dates must be from 1 Jan 1970 until 19 Jan 2038.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜