Datetime vs Date and Time Mysql

后端 未结 4 664
自闭症患者
自闭症患者 2020-12-31 00:19

I generally use datetime field to store created_time updated time of data within an application.

But now i have come across a database table where they have kept dat

4条回答
  •  余生分开走
    2020-12-31 00:38

    I tend to think there are basically no advantages to storing the date and time in separate fields. MySQL offers very convenient functions for extracting the date and time parts of a datetime value.

    Okay. There can be some efficiency reasons. In MySQL, you can put separate indexes on the fields. So, if you want to search for particular times, for instance, then a query that counts by hours of the day (for instance) can use an index on the time field. An index on a datetime field would not be used in this case. A separate date field might make it easier to write a query that will use the date index, but, strictly speaking, a datetime should also work.

    The one time where I've seen dates and times stored separately is in a trading system. In this case, the trade has a valuation date. The valuation time is something like "NY Open" or "London Close" -- this is not a real time value. It is a description of the time of day used for valuation.

提交回复
热议问题