【问题标题】:fetching data from db based on datetime using laravel query使用 laravel 查询根据日期时间从数据库中获取数据
【发布时间】:2015-08-17 18:51:10
【问题描述】:

我正在尝试根据 laravel 中的日期时间从数据库中获取数据。但结果返回空数组。当我在 MYSQL 中使用来自日志文件的原始查询时,它会显示结果。提前致谢

下面是我的 laravel 查询

public function lists(){
$start_date = '20-5-2015';
$end_date = '28-5-2015';
$str_start_date = date("Y-m-d H:i:s",strtotime($start_date));
$str_end_date = date("Y-m-d H:i:s",strtotime($end_date));
$result = DB::table('a')
    ->where('start_date_time','>=',"'$str_start_date'")
    ->where('end_date_time','<=',"'$str_end_date'")
    ->select('a.*')
    ->get();
 dd($result);
}

以下是我对上述 laravel 查询的原始查询

select `a`.* from `a` where `start_date_time` >= '2015-05-20 00:00:00' and `end_date_time` <= '2015-05-28 00:00:00'

【问题讨论】:

    标签: php mysql date datetime laravel


    【解决方案1】:
    ->where('start_date_time','>=',"'$str_start_date'")
                                    ^---------------^
    

    您在值中嵌入了额外的引号...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-07
      • 1970-01-01
      • 2016-04-15
      • 2011-09-26
      • 2017-06-22
      • 1970-01-01
      • 2021-08-20
      • 2019-12-26
      相关资源
      最近更新 更多