FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » validating / converting time for insertion into mysql DB??
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: validating / converting time for insertion into mysql DB?? [message #172217 is a reply to message #172216] Fri, 04 February 2011 18:02 Go to previous messageGo to previous message
PAkerly is currently offline  PAkerly
Messages: 7
Registered: September 2010
Karma:
Junior Member
On Feb 4, 1:00 pm, PAkerly <pake...@gmail.com> wrote:
> On Feb 4, 10:37 am, Michael Fesser <neti...@gmx.de> wrote:
>
>
>
>> .oO(Denis McMahon)
>
>>> […]
>>> And you might also want to consider the following field formats:
>
>>> h/hh:m/mm:s/ss
>>> hmmss
>>> hhmmss
>>> mmss
>>> mss
>
>>> The last two give you problems. How do you tell whether 3 or 4 digits is
>>> hours and minutes or minutes and seconds?
>
>>> The real problem is that you're allowing your user to give you ambiguous
>>> input and then trying to make sense of it.
>
>>> Use more form fields: t1hours t1mins and t2hours t2mins
>
>> While this solves the ambiguity problem, it creates a usability problem
>> and is a pain to use. Even more ugly would be dropdown lists …
>
>> The best method for the user is a single field, and the developer should
>> take care of the correct parsing. You could also enforce a particular
>> format and reject all other ones (of course then there should be a short
>> note or an example near the input field how to enter the time).
>
>>> You could use select lists for hours and minutes
>
>> Arrrgh … ;-)
>
>>> although 60 element
>>> select lists are "too long" for some people's liking.
>
>> People who do this also eat little children.
>
>> Micha
>
> Here is how I display the data on the screen so that even if they
> enter 1215 it shows 12:15
> ....
> <?php echo time_format($_POST[txttime1])?>
>
> Can I also somehow use this to get it into the db this way?

Sorry, forgot to include function...

function time_format($string){
if(preg_match('/^(\d{1,2})([0-5][0-9])$/', $string, $matches))
{
if($matches[1]>=0 && $matches[1]<=23){
return $matches[1] . ':' . $matches[2];
}
}

return $string;

}
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: pass variable in php construct
Next Topic: Looping through Web Service results
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 04:33:08 GMT 2024

Total time taken to generate the page: 0.03922 seconds