Home  >  Article  >  Backend Development  >  Using MySQL Date/Time Type_PHP Tutorial

Using MySQL Date/Time Type_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:53:41726browse

Since I used to be in the same team as him, I am very familiar with his "mesophobic" approach, and I strongly agree with many of his views; but one thing I don't understand very much is that when designing a database, I always Will avoid using Date/Time type. What he did was to set the time-related fields to the INT(10) type, and then use UNIX timestamps to store them. I personally disagree very much with this approach:

First of all, it is the difference in type operations. The "time calculation" similar to wiLdGoose's method is essentially an operation between shaping (and this shaping is very large) , length is 10). What's more, setting the timestamp to VARCHAR(10) causes efficiency problems that are self-evident.

As for the efficiency of time calculation, shaping calculation and even string calculation, this article is very illustrative.

Secondly, there is the operational issue of logic. This is an advantage of using time types, especially on projects that require high precision. For example, if you need "the data of the previous week" and "get the data of every Monday since the database was created", the complexity of such operations can be imagined if you use brother wiLdGoose's method.

Finally, there is the issue of intuitiveness and unintuitiveness. It is understandable that our brains will not directly convert this large series of timestamps into date format. In comparison, it is obviously much more intuitive to use the time type directly (it is a time format itself).

And my current team is still using a similar method. I have also argued about similar technical details for a long time, but due to issues of position and decision-making power, the team still cannot adopt my opinions, which is a pity.

MySQL is positioned as a simple and fast DBM, which can naturally be quickly controlled, but on the other hand, it is easy to create a situation that does not go further. For this, we should pay more attention to the database design details of each item. A product that constantly adds new functions is ultimately application-oriented.

Finally, the official MySQL time and date function manual is attached.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318627.htmlTechArticleSince I used to be in the same team as him, I am very familiar with his "germ-obsessed" approach. I very much agree with many of his views; but there is one thing that I really don’t understand...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn