dongshiran7000 2019-06-08 15:21
浏览 112

在Codeigniter中查询2个日期,仅从日期时间查询日期

I want to query all data between two date fields. The problem I am having is my database has a Datetime field and I only want to query the dates. I normally can get this to work with a like statement but I need to add logic and active record for like does not seem to support this. I used multiple where statements and was able to get this to work by adding "+1days to the to_date field. It seems to work but I don't like it and wonder if there is a better way to go about this. If I dont add the +1 days to my code it only return the < and > and does not return any rows where field = date. Hopefully this makes sense.

I have tried the below code and it does not return anything where date = myInput.

$query = $this->db->select('*')->from('t_clock_punch')
                   ->where('clock_in >=',date("Y-m-d", strtotime($fromDate)))
                   ->where('clock_in <=', date("Y-m-d", strtotime($toDate)))
                   ->get();
    return $query->result_array();
}

I just added a day to my ->where clause and it seems to work just not sure if this is correct and may be problematic later on.

 ->where('clock_in <=', date("Y-m-d", strtotime($toDate . '+1 days')))
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决