Reputation: 141
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 ?!
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.
i didn't used datetime because i just have time only and no need for date.
so, any suggestions?
Upvotes: 2
Views: 4464
Reputation: 6077
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!
Upvotes: 2
Reputation: 2436
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
.
Upvotes: 0