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...

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:

@Cereal - Really appreciate this, I will give it a go and let you know how it works out...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.