MSMC MSMC - 2 years ago 126
SQL Question

Storing html input of type time into MySQL database

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?

Answer Source

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 :


Edit : you can use time format as well :


For more information about how to format you can checkout datetime and time

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download