Page 1 of 1

Convert any time (from a form) into 24 hour format

Posted: Sun Aug 08, 2004 6:56 pm
by paladaxar
I have a field in one of my forms that allows the user to enter a time. I have no set way that I ask them to enter a time but I want to be able to convert any time that is entered into a standard that I can use to add and subtract etc. In other words, a user may enter 9am or 7:15 PM and I want to convert those times into a set format that will write the same type of time to my database every time. I think that the 24 hour system would be the best format. So for the two examples above, I would want to write 09:00 and 19:15 to my database. My biggest problem is that users may enter times in strange ways. I need a way to convert each of these into a workable format. I think I will need to use some type of string replacement, but im not sure. Any ideas? I am fairly new to PHP so try not to use any fancy language when answering my question. thank you.

Posted: Sun Aug 08, 2004 11:45 pm
by feyd
from what I've seen, it's easier to give them drop downs, instead of letting them just enter in a random time.. because the form of it, could be in any number of several hundred ways.. and trying to figure out what they meant just for a simple time is a lot of extra work that I just don't have time to waste on.. personally. But that's only my observations and opinion on it..

As for going about covering some of the combinations for the entering of time, you could check into using [php_man]strtotime[/php_man]