Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP比较两个日期和时间_Php_Date - Fatal编程技术网

PHP比较两个日期和时间

PHP比较两个日期和时间,php,date,Php,Date,我有三个约会A、B和C A = 2013-08-10 10:00 B = 2013-08-10 12:00 C = 2013-08-10 10:22 我要做的是检查C是否在A和B中,是否返回true。有人知道怎么做吗 我试过了,但运气不好 if ($time >= $date_start && $time <= $date_end) { echo "is between\n"; } else { echo 'n

我有三个约会A、B和C

A = 2013-08-10 10:00
B = 2013-08-10 12:00
C = 2013-08-10 10:22
我要做的是检查C是否在A和B中,是否返回true。有人知道怎么做吗

我试过了,但运气不好

    if ($time >= $date_start && $time <= $date_end)
    {
        echo "is between\n";
    } else {
        echo 'no';
    }

如果($time>=$date\u start&&$time使用strotime函数

    $A = "2013-08-10 10:00";
    $B = "2013-08-10 12:00";
    $C = "2013-08-10 10:22";

    if (strtotime($C) > strtotime($A) && strtotime($C) < strtotime($B)){
    echo "The time is between time A and B.";
    }else{
    echo "It is not between time A and B.";
    }
$A=“2013-08-10 10:00”;
$B=“2013-08-10 12:00”;
$C=“2013-08-10 10:22”;
if(strotime($C)>strotime($A)&&strotime($C)
您可以将它们转换为UNIX时间戳进行比较

$A = strtotime($A); //gives value in Unix Timestamp (seconds since 1970)
$B = strtotime($B);
$C = strtotime($C);

if ((($C < $A) && ($C > $B)) || (($C > $A) && ($C < $B)) ){
  echo "Yes '$C' is between '$A' and '$B'";
 }
$A=strotime($A);//给出Unix时间戳中的值(自1970年以来的秒数)
$B=标准时间($B);
$C=标准时间($C);
如果(($C<$A)和($C>$B))| |($C>$A)和($C<$B))){
回显“是”$C'在“$A”和“$B”之间;
}
使用该类:

$A='2013-08-10:00';
$B=‘2013-08-10 12:00’;
$C='2013-08-10 10:22';
$dateA=DateTime::createFromFormat('Y-m-DH:m',$A);
$dateB=DateTime::createFromFormat('Y-m-dh:m',$B);
$dateC=DateTime::createFromFormat('Y-m-DH:m',$C);

如果($dateA>=$dateB&&$dateA使用以下代码比较php中的日期值

                 <?php
               $a = new DateTime("2013-08-10 10:00");

               $b= new DateTime("2013-08-10 12:00");

                  $c = new DateTime('2013-08-10 10:22');
               if(($a<$c)&&($c<$b))
               {
               return true;
               }
            ?>


阅读该选项使用
strotime
函数,并添加check。这很简单。您好,我尝试了此选项,但如果是同一天,则返回true。它忽略了时间。
                 <?php
               $a = new DateTime("2013-08-10 10:00");

               $b= new DateTime("2013-08-10 12:00");

                  $c = new DateTime('2013-08-10 10:22');
               if(($a<$c)&&($c<$b))
               {
               return true;
               }
            ?>