0

Hi Everyone...

I have the following php to check against two vars... $minute & $second

I am making a new var out of the above
$fgt = $minute. "" .$second;

if((strstr($fgt,"45:00")))
    { 

        $hint = 'Error';
        registerError( $hint, $hint, $error_title, '<h3>Error - Goal Time Can Not Be Greater Than <strong>(45:00)</strong></h3>' );
        $b1=false;
    }

On my form, Users can select from minute 01: (from 1-90)
and select seconds also (from 00 to 59)

I am trying to catch and display an error message to the user if they select 45 minutes and any number of seconds above 00

So if the user selects ( 45:01 - 45:59 ) I would like to display the error message to them...

2
Contributors
2
Replies
23
Views
3 Years
Discussion Span
Last Post by everton.retweets
0

Try with the DateTime class:

<?php

$minute = 45;
$second = 01;

# value to test
$test = new DateTime();
$time = $test->setTime(0, $minute, $second);

# match this
$minDate = new DateTime();
$min = $minDate->setTime(0, 45, 0);

if($min->diff($time)->i == 0 && $minute == 45 && $min->diff($time)->s > 0)
{
    echo 'Alert';
}
else
{
    echo 'Ok';
}

Note that the difference for the minute $min->diff($time)->i will return 0 for all the values between 44:01 and 45:59, so it is important to check also the value of the original variable $minute, and to restrict the match only to 45:01 - 45:59 we have to check also the seconds with $min->diff($time)->s > 0.

Docs:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.