so scene is, have store opens @ 1:00am @ night, , closes @ 10:00pm. current time want check whether timestamp lies between store open , close times.
yeap that's simple, , still don't know why, finding difficult. below piece of epic shit trying.
<?php $t=time(); //for current time $o = date("y-m-d ",$t)."01:00:00"; //store open @ time $c = date("y-m-d ",$t)."22:00:00"; //store closes @ time //yes, crazy .. love echoing variables echo "current time = ".$t; echo php_eol; echo "start = ".strtotime($o); echo php_eol; echo "end = ".strtotime($c); echo php_eol; // below condition runs well, $t greater $o if($t>$o){ echo "open_c1"; }else{ echo "close_c1"; } //here's variable $t, behaves little terrorist , proclaims greater $c if($t<$c){ echo "open_c2"; }else{ echo "close_c2"; } ?>
output: on phpfiddle
current time = 1472765602 start = 1472706000 end = 1472781600 open_c1 close_c2
just 1 help, why ( $t < $c ) condition false. missing common or making serious blunder.
thank you.
try instead
$o = date("y-m-d 01:00:00"); //store open @ time $c = date("y-m-d 22:00:00"); //store closes @ time
Comments
Post a Comment