dongmiyu8979 2013-10-09 09:26
浏览 115
已采纳

为什么我的MySQL BETWEEN运算符不能正常工作?

MySQL table "flightSched" is connected to time, similar to the one below:

flightNo    |day    |time   |arrivalTimeSec
=============================================
WERE112 |Tuesday    | 1:00  |1381186800
FGHG234 |Tuesday    |23:00  |1381266000
CGHF345 |Tuesday    |00:00  |1381183200

I have a mysql query that select all data between two times. This is the query:

$CurrentTimeMinus30min = date('H:i', strtotime('-30 minutes')); //Current Time minus 30minutes
$CurrentTimeMinus30min = strtotime($CurrentTimeMinus30min);     

$CurrentTimePlus4Hours = date('H:i', strtotime('+240 minutes')); //Current Time plus 4 hours
$CurrentTimePlus4Hours = strtotime($CurrentTimePlus4Hours);

$query = $mysqli->query("
    SELECT * FROM flightSched 
    WHERE day = '$currentDay' 
    AND arrivalTimeSec 
        BETWEEN '$CurrentTimeMinus30min' 
        AND '$CurrentTimePlus4Hours'
");

I was advised to used strtotime() function on the time values to be able to use them in a BETWEEN MySQL query. This doesn't seem to be working at all.

Where am I going wrong with this query? Any help will be appreciated.

  • 写回答

4条回答 默认 最新

  • douju2014 2014-07-15 00:08
    关注

    today I found the same problem with yours (mine about coordinates). and I found out that in some case, a BETWEEN operator can only be used like this

    ..... WHERE columname BETWEEN smallervalue AND biggervalue
    

    previously I've tried with the biggervalue at front since I dealt with negative numbers, and it fails. you might found the same problem with your timestamp.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试