DATETIME VS INT to store time?

Which one is best to use, DateTime or INT (Unix timestamp) or something else to keep the time value?

I think INT will be better in performance as well as more versatile, as it can easily be converted to many time zones. (my visitors from around the world can see the time without confusion)

But I still doubt it. Any suggestions?

+4
source share
2 answers

I would not use INTor TIMESTAMPto save your datetime values. There is a "Year-2038-Problem" ! You can use DATETIMEand save your dates for a long time.

With TIMESTAMPor numeric column types, you can only store years from 1970 to 2038. With a type, DATETIMEyou can store dates with years from 1000 to 9999.

It is not recommended to use a numeric column type ( INT) to store time and time information. MySQL (and other sytems too) provides many functions for processing time and time information. These functions are faster and more optimized than user-defined functions or calculations: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html

, CONVERT_TZ. . , .

+4

TIMESTAMP , . , TIMESTAMP .

, , :

CONVERT_TZ(@dt,'US/Central','Europe/Berlin') AS Berlin,

int, MySQL Cookbook Paul DuBois, . quetion.

+2

Source: https://habr.com/ru/post/1676020/


All Articles