Comparing the time of mktime in php

The question was asked: 6 years 11 months ago   views: 16
0
$uFrom = 1340348400;
$uTo = 1340409600;
$time = 1340310456;
$bWork = ($uFrom <= $time and $uTo > $time) ? 1 : 0;

Get 0. Why is this happening?

Asked: Tchort Tchort 22-06-2012 в 00:29:40

Answers   2

0

Probably because just $uFrom > $time =)

$bWork = ($uFrom <= $time && $uTo > $time) ? 1 : 0;

This design assigns one if ($uFrom <= $time && $uTo > $time)==true, and this design in turn returns trueonly if both conditions is true. In your case this is not happening. You get that !($uFrom <= $time)==true, ie ($uFrom > $time)==true. You should use or, however, it depends on your task.

UPD:

$c = 7; // date("H"); current time(in hours)
for($i=1;$i<=24;$i++) // here is a demonstration for each hour
{
echo $i." => ";
if($i < 4 || $i > 11) print("Open!"); else print("Close"); echo("<br>");
}

Finished the algorithm to the mind or to write back( to determine when closed ), I think you will not be difficult.

Answered: AseN AseN 22-06-2012 в 01:28:37
For example, opening at 11 a.m., closing at 4 o'clock. Now the hour of the night, and the object is closed. Because mktime hour of the night less than 11 am. - Tchort Tchort 22-06-2012 в 01:33:40
Well, all right! --- And you need to determine whether the object is closed? - AseN AseN 22-06-2012 в 01:35:36
Yes, in the morning he is supposed to be opened. If it works from 11 am to 4 nights. - Tchort Tchort 22-06-2012 в 01:41:03
For example if you write: echo "C ".date("H:i:s",$uFrom)."
"; echo "Now ".date("H:i:s",$uTime)."
"; echo "For ".date("H:i:s",$uTo)."

"; return C 11:00:00 right Now 03:00:00 04:00:00 - Tchort Tchort 22-06-2012 в 01:47:16
Added reply. - AseN AseN 22-06-2012 в 01:48:08
0

$uFrom > $time 1340348400 > 1340310456

Answered: ReinRaus ReinRaus 22-06-2012 в 01:02:20