Time occurs between two time
Time occurs between two time
am 03.08.2007 12:14:18 von Kesavan Muthuvel
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
am 03.08.2007 13:37:42 von Jerry Stuckle
Kesavan wrote:
> 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.
>
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
am 03.08.2007 16:44:46 von gosha bine
On 03.08.2007 13:37 Jerry Stuckle wrote:
> Kesavan wrote:
>> 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.
>>
>
> 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.
>
Times in H:i:s format can be perfectly compared as strings.
--
gosha bine
makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Re: Time occurs between two time
am 03.08.2007 16:54:05 von ELINTPimp
> > 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.
>
> Times in H:i:s format can be perfectly compared as strings.
>
yup, currently doing it in a small project I'm working on.
your function:
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
am 03.08.2007 19:05:24 von Toby A Inkster
Kesavan wrote:
> if( $time1>$nowTime && $time2<$nowTime)
> return true;
> else
> return false;
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;
instead.
--
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
am 03.08.2007 19:07:18 von Toby A Inkster
Kesavan wrote:
> I need a function such it returns true when current time occurs
> between the parameters.
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/