What should i use to save date and time
This question already has an answer here:
For my new database i want to save a given date and time and year from php to my database
So, store it as DATETIME
. It includes the year.
Here is how look at those types:
DATE
: use for dates (with years), for example aa birthdate ("2010-11-23")
TIME
: use for a time in a day, for example the start of your lunch ("12:00")
DATETIME
: use for a specific date and time, for example the start of a meeting ("2010-11-23 12:00")
TIMESTAMP
: use for when a specific thing happened, for example the time a certain meeting was created ("1385653500"; this often includes timezone information in its definition)
YEAR
: use to store a year, for example the start year of a war ("1653")
Note that you can always cast "larger" types to "smaller" types. Eg you can cast a DATE
into a YEAR
.
上一篇: Rails 4:可用数据类型的列表
下一篇: 我应该用什么来节省日期和时间