シーンはなので、夜は午前1時にオープンし、午後10時に閉じるストアがあります。 現時点では、タイムスタンプが店舗の開店時間と閉店時間の間にあるかどうかをチェックしたいだけです。phpの2つのタイムスタンプを比較する
これは非常に単純ですが、それでも私はなぜそれが難しいか分かりません。下の は私が試している壮大なたわごとです。
<?php
$t=time(); //for current time
$o = date("Y-m-d ",$t)."01:00:00"; //store open at this time
$c = date("Y-m-d ",$t)."22:00:00"; //store closes at this time
//Yes, its crazy .. but I 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 is always greater than $o
if($t>$o){
echo "Open_c1";
}else{
echo "Close_c1";
}
//Here's where my variable $t, behaves like a little terrorist and proclaims itself greater than $c
if($t<$c){
echo "Open_c2";
}else{
echo "Close_c2";
}
?>
OUTPUT:phpfiddle上
現在の時刻= 1472765602スタート= 1472706000終了= 1472781600 Open_c1 Close_c2
ジャスト($ T < $ c)は条件が偽である理由1つのヘルプ、。 私は何か非常に一般的なものを見逃しているか、深刻な大失敗をしていますか?
ありがとうございます。
私の悪いところです。$ o&$ cを文字列に変換するのを忘れて、日付を文字列と比較していました。 – Sarge