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

Home » Imported messages » comp.lang.php » Verifying time in php
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Verifying time in php [message #179392 is a reply to message #179375] Sun, 14 October 2012 19:28 Go to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma:
Senior Member
On 14-10-2012 11:45, houghi wrote:
> I have a form that has the following entry fields:
> hours
> minutes
> seconds
>
> I need the time in seconds and that works:
> $realtime=$_POST['hours']*3600+$_POST['minutes']*60+$_POST['seconds'];
>
> However people can fill out nothing or they could enter characters
>
> What is the easiest way to verify if what the people filled out is
> correct? I have tried, but I get lost in the if statements.
>
> Extra difficult is that they must not fill out all three. Only one is
> enough. e.g.
> 1 hour and no minutes or second gives 3600
> 1 hour, 1 minute and 1 second gives 3661
> 1 hour and 'X' should give an error.
> All empty should give an error
> empty hour 70 minutes and 75 seconds gives 4275.
> Hours of more then 24 will be possible as well.
> I might even add number of days.
>
> If the last one gives an error, but it makes the life much easier, I can
> live with that
>
> It is the fact that they do not need to fill out all three that I am
> stuck.
>
> What I have tried is first to see if all are empty
> Next try to see if each one is not a number
> Then I need to figure out if there is a combination of some of it.
>
> And that is when I get lost in the if statements and loops in loops.
>
> I am sure there is an easy way to tell if all is nice and works well,
> but how? Seaching google gave me transfering from seconds to H:i:s, but
> that is not what I want.
>
> houghi
>

whats wrong with this code:
<?php
$h=13;
$m=14;
$s=15;
$t=sprintf("%02d:%02d:%02d", $h, $m, $s);
$x=strtotime($t);
print $x."\n";
print date("l dS F Y H:i:s ",$x)."\n";

You only need some more validation on the 'strtotime' and 'date'
functions.....
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Curl chmod file transfer problem...
Next Topic: test
Goto Forum:
  

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

Current Time: Sun Nov 24 12:37:37 GMT 2024

Total time taken to generate the page: 0.04458 seconds