This question already has an answer here:
这个问题在这里已有答案:
- Should I use the datetime or timestamp data type in MySQL? 35 answers
我应该在MySQL中使用日期时间或时间戳数据类型吗? 35个答案
I am creating a table which has create_date and modify_date field in mysql, but I am struggling in decide which data type is the best choice for these 2 fields. Should i use date time for both fields, or should i use date time for create_date and time stamp for modify_date ?
我正在创建一个在mysql中有create_date和modify_date字段的表,但是我很难确定哪个数据类型是这两个字段的最佳选择。我应该使用两个字段的日期时间,还是应该使用create_date的日期时间和modify_date的时间戳?
3 个解决方案
#1
0
I'm assuming you're talking about a database table. If that is the case and you need to know date information choose a date time for both modify_date
and create_date
. If you don't need date information use a time stamp.
我假设你在谈论数据库表。如果是这种情况,您需要知道日期信息,请选择modify_date和create_date的日期时间。如果您不需要日期信息,请使用时间戳。
#2
1
Depends on your requirements. If you want to know the exact time these things happened then use a date/time (DATETIME in MySQL). Or, if you're happy with with just the date then choose date (DATE in MySQL)! If you don't know when maybe use DATETIME just to be safe (so you have the precision if you need it).
取决于您的要求。如果你想知道这些事情发生的确切时间,那么使用日期/时间(MySQL中的DATETIME)。或者,如果您对日期感到满意,那么选择日期(MySQL中的DATE)!如果你不知道什么时候可以使用DATETIME只是为了安全(所以如果你需要它你有精度)。
You're using MySQL so here is the documentation: http://dev.mysql.com/doc/refman/5.0/en/datetime.html
你正在使用MySQL所以这里是文档:http://dev.mysql.com/doc/refman/5.0/en/datetime.html
#3
0
Sorry I'm from Ukraine and I use Google Translate. It all depends on how you are going to use them, if you take away from each other then TimeStamp, if just to show (for example in the news), then it is better Date Time. Generally I recommend TimeStamp
抱歉,我来自乌克兰,我使用谷歌翻译。这一切都取决于你将如何使用它们,如果你相互带走然后TimeStamp,如果只是为了显示(例如在新闻中),那么它是更好的日期时间。一般来说,我推荐TimeStamp
#1
0
I'm assuming you're talking about a database table. If that is the case and you need to know date information choose a date time for both modify_date
and create_date
. If you don't need date information use a time stamp.
我假设你在谈论数据库表。如果是这种情况,您需要知道日期信息,请选择modify_date和create_date的日期时间。如果您不需要日期信息,请使用时间戳。
#2
1
Depends on your requirements. If you want to know the exact time these things happened then use a date/time (DATETIME in MySQL). Or, if you're happy with with just the date then choose date (DATE in MySQL)! If you don't know when maybe use DATETIME just to be safe (so you have the precision if you need it).
取决于您的要求。如果你想知道这些事情发生的确切时间,那么使用日期/时间(MySQL中的DATETIME)。或者,如果您对日期感到满意,那么选择日期(MySQL中的DATE)!如果你不知道什么时候可以使用DATETIME只是为了安全(所以如果你需要它你有精度)。
You're using MySQL so here is the documentation: http://dev.mysql.com/doc/refman/5.0/en/datetime.html
你正在使用MySQL所以这里是文档:http://dev.mysql.com/doc/refman/5.0/en/datetime.html
#3
0
Sorry I'm from Ukraine and I use Google Translate. It all depends on how you are going to use them, if you take away from each other then TimeStamp, if just to show (for example in the news), then it is better Date Time. Generally I recommend TimeStamp
抱歉,我来自乌克兰,我使用谷歌翻译。这一切都取决于你将如何使用它们,如果你相互带走然后TimeStamp,如果只是为了显示(例如在新闻中),那么它是更好的日期时间。一般来说,我推荐TimeStamp