2

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?

1

2 Answers 2

2

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!

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.