How to query sql with active record for dates between specified times(如何使用活动记录查询指定时间之间日期的sql)
问题描述
我有一个数据库,我只想提取日期在指定范围内的某些行.我不确定如何在活动记录中正确执行此操作.现在看起来我正在活动记录查询中运行标准的 mysql 查询.我希望这能让你知道我在寻找什么.
I have a database that I want to pull only certain rows that have dates in specified ranges. I'm not sure how to do this properly in active record. Right now it looks like I'm running a standard mysql query inside of an active record query. I hope this gives you the idea of what I'm looking for.
我还希望能够获取包含今天之前的任何内容的行,包括今天和未来 3 天.
I would also like to be able to get rows with anything before today, including today and 3 days in the future.
$query = $this->db->query("SELECT * FROM 'topics_list' . 'topic date' WHERE DATE(order_datetime) BETWEEN '2012-10-01' AND '2012-10-3'");
推荐答案
这就是方法.但根据您在数据库中的 DATE 格式,您必须更改 2012-10-01
和 2012-10-03
this is the way . but according to the DATE format you have in the database you have to change 2012-10-01
and 2012-10-03
$this->db->select('*');
$this->db->from('topics_list');
$this->db->where('order_datetime <','2012-10-03');
$this->db->where('order_datetime >','2012-10-01');
$result = $this->db->get();
这篇关于如何使用活动记录查询指定时间之间日期的sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用活动记录查询指定时间之间日期的sql


基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01