View Full Version : Time From Form to Database(MySQL)

03-01-2007, 08:56 PM
I have a form and I'm trying to decide the best way to ask the user for the time they want to schedule the event. Should I just have a text field or should I use a list with options. I would prefer to ask for the time in 12-hour format and ask whether or not it's AM/PM.

I know I will have to convert the time to 24-hour format. I'm just having trouble working out all the details of getting it from 12-hr to 24-hr so I can post it to the database.

Thanks for your help.

03-01-2007, 09:24 PM
I would make a single selection list that contains all the times available (10am, 11am, noon, 1pm, etc) and then use strtotime() (http://us3.php.net/manual/en/function.strtotime.php) to convert it into a "time" data type to store in MySQL.

03-02-2007, 12:07 AM
If you're generating a list of times, then why risk strtotime()?

Just use the timestamp as the value in the selection list.

But if you want non specific times (not in hour increments/not a drop down) then you should probably use strtotime().

It's quite nice as long as you guide the user somewhat.

03-02-2007, 12:09 AM
Thanks for the help. I think I got it with a combination of strtotime() and strftime().