# Time occurs between two time

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
I need a function such it returns true when current time occurs
between the parameters.

function checkTime(\$time1,\$time2){
\$nowTime=date("H:i:s");

//MY LOGIC IS

if( \$time1>\$nowTime && \$time2<\$nowTime)

///

return true;
else
return false;

}

plz guide me  the function run.

## Re: Time occurs between two time

Kesavan wrote:

You can't compare times as strings and expect it to work.  You need to
first convert them to a numeric value, i.e. unixtime format.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: Time occurs between two time

On 03.08.2007 13:37 Jerry Stuckle wrote:

Times in H:i:s format can be perfectly compared as strings.

--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell

## Re: Time occurs between two time

yup, currently doing it in a small project I'm working on.

function checkTime(\$time1,\$time2){
\$nowTime=date("H:i:s");
//do validation on \$time1 and \$time2 to ensure H:i:s format

if( \$time1>\$nowTime && \$time2<\$nowTime) {
return true;
}
else {
return false;
}
} // end checkTime

your function, which stripped of validation and exception handling,
looks like it should work (so long as \$time1 and \$time2 are in H:i:s
format.  What's the problem?

## Re: Time occurs between two time

Kesavan wrote:

This can be abbreviated as:

return (\$time1>\$nowTime && \$time2<\$nowTime);

Whenever you find yourself writing:

if (X) return true;
else   return false;

Just write:

return X;

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 43 days, 20:43.]

Command Line Interfaces, Again
http://tobyinkster.co.uk/blog/2007/08/02/command-line-again/

## Re: Time occurs between two time

Kesavan wrote:

Technically speaking, the following function meets the above
specification:

function checkTime () { return TRUE; }

Although I know what you *meant*, it pays to be fairly specific
around here.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 43 days, 20:46.]

Command Line Interfaces, Again
http://tobyinkster.co.uk/blog/2007/08/02/command-line-again/