Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.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 使用mysql比较小于或大于记录之间的记录_Php_Mysql_Datetime - Fatal编程技术网

Php 使用mysql比较小于或大于记录之间的记录

Php 使用mysql比较小于或大于记录之间的记录,php,mysql,datetime,Php,Mysql,Datetime,我的问题是比较= 我的表包含列ID、名称、地址、堆栈、StartDateTime、EndDateTime。 我想获取StartDateTime和EndDateTime之间的记录。 日期时间格式为0000-00-00:00:00 mysql-> Select * from Table_nm where StartDateTime>= $DATETIME and EndDateTime<= $DATETIME1; 就像wise记录包含日期时间一样, 所以,给我下面显示的过滤器的

我的问题是比较
=
我的表包含列ID、名称、地址、堆栈、StartDateTime、EndDateTime。 我想获取
StartDateTime
EndDateTime
之间的记录。 日期时间格式为
0000-00-00:00:00

mysql-> Select * from Table_nm where  StartDateTime>= $DATETIME and EndDateTime<= $DATETIME1;
就像wise记录包含日期时间一样, 所以,给我下面显示的过滤器的结果

1.If I want to filter record where StartDateTime>=2015-02-03 00:00:00 and EndDateTime<= 2015-02-06 00:00:00.
2.If I want to filter record where StartDateTime>=2015-02-03 09:00:00 and EndDateTime<= 2015-02-06 12:00:00.
3.If I want to filter record where StartDateTime>=2015-02-03 01:00:00 and EndDateTime<= 2015-02-06 22:00:00.

1.如果我想筛选StartDateTime>=2015-02-03 00:00:00和EndDateTime=2015-02-03 09:00:00和EndDateTime=2015-02-03 01:00:00和EndDateTime=
的记录,我会使用
时间差戳

在您的示例中,它类似于:

mysql-> Select * from Table_nm
        where TIMESTAMPDIFF(SECOND, `StartDateTime`, '$DATETIME')>= 0
          and TIMESTAMPDIFF(SECOND, `EndDateTime`, '$DATETIME1')<= 0;
mysql->从表中选择*
其中TIMESTAMPDIFF(秒,`StartDateTime`,'$DATETIME')>=0

TIMESTAMPDIFF(第二个,`EndDateTime`,'$DATETIME1')也向我显示您的结果,当您运行上述查询时,结果会是什么,如果确实有行满足该条件是的,它会工作,但我想知道如何在mysql的后端进行比较。同时,我想搜索(2个)记录。该时间仅显示此时间范围之间的时间范围?见f(1号)记录。我搜索时间12到12是在所有记录之间显示还是只显示谁的时间
=
到00:00:00它是如何工作的,它只显示开始日期和结束日期以及开始时间和结束时间之间的记录?这是它应该做的,试试看。如果假设我使用函数(时间戳(“2015-02-03”,“10:00”),秒)像这样,那么呢?可能有很多解决办法。你可以试试我贴的那个,或者想出另一个办法。不!不准确的记录。它也显示不同的值。接近StartDateTime列和End DateTIme列。
mysql-> Select * from Table_nm
        where TIMESTAMPDIFF(SECOND, `StartDateTime`, '$DATETIME')>= 0
          and TIMESTAMPDIFF(SECOND, `EndDateTime`, '$DATETIME1')<= 0;