如何在MySQL中使用TIME类型?

时间:2021-12-29 16:06:14

I'm building my first DB through MySQL Workbench. In a table I need to store a time attribute that contains minutes and seconds. In this regard, I wanted to use the TIME data type. What is the argument required by the type TIME(...)?

我正在通过MySQL Workbench构建我的第一个数据库。在表中,我需要存储包含分钟和秒的时间属性。在这方面,我想使用TIME数据类型。 TIME(...)类型所需的参数是什么?

2 个解决方案

#1


6  

I solved, I entered TIME without parentheses. I thought that the type TIME required an input parameter.

我解决了,我没有括号进入TIME。我认为TIME类型需要一个输入参数。

CREATE TABLE IF NOT EXISTS CookingDB.Recipe ( ... CookingTime TIME NULL, ...

CREATE TABLE如果不存在CookingDB.Recipe(... CookingTime TIME NULL,...

#2


1  

As said in MYSQL docs:

如在MYSQL文档中所述:

MySQL retrieves and displays TIME values in 'HH:MM:SS' format

MySQL以'HH:MM:SS'格式检索并显示TIME值

You have to use the TIME data type to represent the time of the day however to store only the minutes and seconds you need to use the DATE_FORMAT to format your time in your desired format.

您必须使用TIME数据类型来表示一天中的时间,但是只存储您需要使用DATE_FORMAT以所需格式格式化时间所需的分钟和秒数。

On a side note, do note that TIME datatype takes 3 bytes of space.

另请注意,请注意TIME数据类型占用3个字节的空间。

#1


6  

I solved, I entered TIME without parentheses. I thought that the type TIME required an input parameter.

我解决了,我没有括号进入TIME。我认为TIME类型需要一个输入参数。

CREATE TABLE IF NOT EXISTS CookingDB.Recipe ( ... CookingTime TIME NULL, ...

CREATE TABLE如果不存在CookingDB.Recipe(... CookingTime TIME NULL,...

#2


1  

As said in MYSQL docs:

如在MYSQL文档中所述:

MySQL retrieves and displays TIME values in 'HH:MM:SS' format

MySQL以'HH:MM:SS'格式检索并显示TIME值

You have to use the TIME data type to represent the time of the day however to store only the minutes and seconds you need to use the DATE_FORMAT to format your time in your desired format.

您必须使用TIME数据类型来表示一天中的时间,但是只存储您需要使用DATE_FORMAT以所需格式格式化时间所需的分钟和秒数。

On a side note, do note that TIME datatype takes 3 bytes of space.

另请注意,请注意TIME数据类型占用3个字节的空间。