No matter what the project is, you have to contact the time type. Currently, using timestamps to store date data (for integer storage) is already a common practice in the industry. Various online game companies and major open-source companies use integer timestamps for storage. There are many benefits for saving an integer to a date,ProgramDetermine Direct Read, good scalability, and convertible XML, JSON, and other formats at will. However, the biggest drawback is that the database query is not intuitive. That is to say, when we open the database using management tools, we see a bunch of numbers, which makes it inconvenient to maintain data. In order to solve this problem, I find a solution first.Code:
Select*, Date_format (from_unixtime (Datetimed/1000),"%Y-%M ")From'Testtable'
Testtable is the table name, And datetimed is an integer field in the table. I am using millisecond storage, but MySQL's from_unixtime method can only be converted to seconds, so it is calculated in/1000.
If you have used Weaver dream, all open-source discuz friends may have experienced a bunch of headaches and integer time. This MySQL statement sticks to the management tool to run and you can see the date result intuitively.
However, if someone finds this troublesome, I have nothing to say. After all, some people do not need to consider expansion or use object format conversion for small projects. The operations in the background basically do not use date. They convert date to an integer before calculation. Why is it a waste of time and energy to save a date type that is not easy to convert to the format. Timestamp is used by many large open-source platforms, which proves the advantages of Timestamp storage. Is this worth giving up expansion for a quick and intuitive purpose?