Envious
Envious

Reputation: 487

HTML5 input time from 24 hour to 12 hour

I have an HTML5 that uses an <input> tag with type"time" which submits into MySQL using PHP. The problem is, the "time" is using a 24 hour format 00:00:00 which doesn't make sense to the end user.

I want to be able to have the user enter it in 12 hour format and also have it display on a separate page where the results are posted from MySQL in a 12 hour format.

What's the easiest way to do this? It's a website that keeps track of when a customer walks in and leaves the lab. So being able to subtract those results is crucial. What I have right now (the 24 hour format) works just fine for our purposes (and subtracts to display total time spent) but the 24 hour format is an issue which if solved could be very useful to us.

Upvotes: 1

Views: 2797

Answers (1)

quentinxs
quentinxs

Reputation: 866

The only way I can see doing this is to set the min and max values for the input to 01:00:00 and 12:59:59, respectively, and add a drop down menu for selecting AM or PM next to it.

Of course by doing this you'll have convert all the times back to 24-hour when the user submits the form, so you can store them in the database.

Upvotes: 2

Related Questions