hope you fine and well,
希望你好,
i have an html form that contains input of type time, what is the better datatype that i can use to store the input value in MySQL ?!
我有一个包含time类型输入的html表单,我可以用来在MySQL中存储输入值的更好的数据类型是什么?!
below is the input:
以下是输入:
<td align="center">Time<input type="time" name="start">
i used varchar type, but i think it will cause problems in the future if i need to compare stored time with current time for example.
我使用varchar类型,但我认为如果我需要将存储时间与当前时间进行比较,它将在未来引起问题。
i didn't used datetime because i just have time only and no need for date.
我没有使用datetime,因为我只有时间,不需要约会。
so, any suggestions?
那么,有什么建议吗?
2 个解决方案
#1
1
I think the best way to achieve this, still by storing datetime when you create your database (maybe you will need date later for any kind of test ) but when you want to retrive it just use the right format like this :
我认为实现这一目标的最佳方法仍然是在创建数据库时存储日期时间(可能以后需要日期进行任何类型的测试),但是当您想要检索它时,只需使用正确的格式,如下所示:
SELECT DATE_FORMAT(colName,'%H:%i:%s') TIMEONLY
Edit : you can use time format as well :
编辑:您也可以使用时间格式:
SELECT TIME_FORMAT(colName, 'HH:MM:SS')
For more information about how to format you can checkout datetime and time
有关如何格式化的更多信息,您可以查看日期时间和时间
Hope this helps!
希望这可以帮助!
#2
0
There is Time Type Which you can use.
有时间类型您可以使用。
MySQL retrieves and displays TIME values in HH:MM:SS
format (or HHH:MM:SS
format for large hours values). TIME values may range from -838:59:59
to 838:59:59
.
MySQL以HH:MM:SS格式(或HHH:MM:SS格式,用于大小时值)检索并显示TIME值。 TIME值的范围可以从-838:59:59到838:59:59。
#1
1
I think the best way to achieve this, still by storing datetime when you create your database (maybe you will need date later for any kind of test ) but when you want to retrive it just use the right format like this :
我认为实现这一目标的最佳方法仍然是在创建数据库时存储日期时间(可能以后需要日期进行任何类型的测试),但是当您想要检索它时,只需使用正确的格式,如下所示:
SELECT DATE_FORMAT(colName,'%H:%i:%s') TIMEONLY
Edit : you can use time format as well :
编辑:您也可以使用时间格式:
SELECT TIME_FORMAT(colName, 'HH:MM:SS')
For more information about how to format you can checkout datetime and time
有关如何格式化的更多信息,您可以查看日期时间和时间
Hope this helps!
希望这可以帮助!
#2
0
There is Time Type Which you can use.
有时间类型您可以使用。
MySQL retrieves and displays TIME values in HH:MM:SS
format (or HHH:MM:SS
format for large hours values). TIME values may range from -838:59:59
to 838:59:59
.
MySQL以HH:MM:SS格式(或HHH:MM:SS格式,用于大小时值)检索并显示TIME值。 TIME值的范围可以从-838:59:59到838:59:59。