【问题标题】:Laravel Query Builder - Query on Date Not WorkingLaravel 查询生成器 - 查询日期不工作
【发布时间】:2015-12-16 06:53:24
【问题描述】:

我在 Laravel 查询生成器中有这样的查询-

    $baseQuery  =   DB::table(  'project');
    //$startDate="2015-09-02" - This format
    //$endtDate="2014-08-02" - This format
    if(!empty($startDate))
        $baseQuery  =   $baseQuery->where('project.completion_date', '>', $startDate);
    if(!empty($endData))
        $baseQuery  =   $baseQuery->where('project.completion_date', '<', $endData);

【问题讨论】:

  • 什么不起作用? if(!empty($endData)) 正确吗? (不应该是if(!empty($endDate)) 或你的$endtDate?)
  • 确实,有什么问题?

标签: mysql laravel laravel-4 laravel-5 query-builder


【解决方案1】:

试试这个

$startDate = empty($startDate) ? '1970-01-01' : $startDate;
$endDate = empty($endDate) ? '2038-01-01' : $endDate;

DB::table('project')
    ->whereBetween('completion_date', [$startDate, $endDate])
    ->get();

【讨论】:

  • 不,这不是因为你看到任何数据都可以是空的
猜你喜欢
  • 1970-01-01
  • 2018-08-08
  • 2015-12-13
  • 2020-03-16
  • 1970-01-01
  • 2019-02-14
  • 1970-01-01
  • 2016-07-21
  • 1970-01-01
相关资源
最近更新 更多