PHP If condition between two times -


i have case box of text should not shown between 2 times example 20 , 01 (24-hour clock), should work, when choose not show box betweem 20 , 22 example.

but if have:

$start = "20"; $end = "01"; $now = date('h');  if($now > $start , $now < $end) {   echo "dont show box"; } else {   echo "show box"; } 

how can convert numbers, can use mktime() if don't have date? because box should activated every day in time range.

you don't want show box between 20:00 01:00

currently logic kinda messed in if($now > $start , $now < $end).

if expect $start = 20 , $end = 1, then kind of value $now might more 20 , less 1.

your if statement logic go else whatever value of $now is.

but there's workaround switch logic this.

you want show box between 02:00 19:00

instead of other way around.

so can this,

$start = "20"; $end = "01"; $now = date('h');  if ($now > $end && $now < $start) {     echo "show box"; } else {     echo "don't show"; } 

update 1:

now, don't want show box between 20:00 22:00

you can vice versa or current logic. like,

$start = "20"; $end = "22"; $now = date('h');  if ($now >= $start && $now <= $end) {     echo "don't show"; } else {     echo "show box"; } 

update 2:

if $start or $end varies, can wrap them in if condition. like,

if ($start > $end) {     if ($now > $end && $now < $start)     {         echo "show box";     }     else     {         echo "don't show";     } } else if ($start < $end) {     if ($now >= $start && $now <= $end)     {         echo "don't show";     }     else     {         echo "show box";     } } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -