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 #179395 is a reply to message #179378] Sun, 14 October 2012 21:12 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Sun, 14 Oct 2012 13:50:51 +0200, houghi wrote:

> Denis McMahon wrote:
>>> 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.
>>
>> Verify it is correct in what way?
>>
>> If you want to record the time the data was entered, it would make more
>> sense to use the system time, and not collect the data in the form at
>> all.
>>
>> If you want the user to specify the time that an event happened in the
>> past, or is to happen in the future, give them a select list with
>> options of 1-31 for day, Jan-Dec for month, <whatever range suits> for
>> year, 00-23 for hours, 00-59 for mins, 00-59 for seconds. Convert the
>> form data to an actual timestamp and do whatever validation and
>> verification you want.
>
> Sorry for the confiusion. I hope the link I gave clariefied things a
> bit. http://houghi/gopro.php You can enter the number of hours, minutes
> and seconds yourself.
> So it is to verify if the human entry is correct.
> This is used for calcualtions.
>
> Say that somebody would like to do a timelaps over a period of 8 hours
> with an interval of 1 image every second and a framrate of 30. This
> would result in a movie that is 16 minutes long.
>
> The time can be almost anything. You could have a project that takes 10
> days (240 hours) and with a 60 second interval that would be an 8 minute
> movie.
>
> So one can fill out hours, minutes and seconds. However if nothing is
> filled out, it is not correct. At least one must be filled out.
> Also it must be numbers and not nececerily limited to 59 minutes. If you
> have a detail of 117 minutes, you should be able to do that and not
> first calculate back to 1 hour and 57 minutes.
> So dropdown is not an option (And I dislike dropdown options for
> minutes)
>
> So it is not so much time as it is duration.
>
> I am able to test each if there is a numeric field. I can't get the
> combination of the fields working:
> 1) One of the time fields must be filled out.
> 2) None of the time fields must contain non-digits.

OK, given three values in your form:

<p>Hours: <input type="text" size="4" name="hours"><br>

Minutes: <input type="text" size="4" name="mins"><br>

Seconds: <input type="text" size="4" name="secs"></p>

Then:

<?php

$secs = 0;

if ( isset( $_POST["hours"] ) )
$secs += 3600 * intval( $_POST["hours"] );

if ( isset( $_POST["mins"] ) )
$secs += 60 * intval( $_POST["mins"] );

if ( isset( $_POST["secs"] ) )
$secs += intval( $_POST["secs"] );

// $secs is now the combined value of
// whatever your hours, minutes and
// seconds inputs were, apply some limits

$secs = max( $secs, 1 );
$secs = min( $secs, 86400 );

// now if you want you can normalise $secs
// into hours : minutes : seconds

$hh = $secs / 3600;
$mm = ( $secs - $hh * 3600 ) / 60;
$ss = ( $secs - $hh * 3600 ) % 60;

$timestr = sprintf( "%02d:%02d:%02d", $hh, $mm, $ss );

?>

Unless I've totally misunderstood the problem, which is quite possible.

Rgds

Denis McMahon
[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:36:17 GMT 2024

Total time taken to generate the page: 0.05349 seconds