gpt4 book ai didi

mysql - Laravel 查询生成器 - 日期查询不起作用

转载 作者:行者123 更新时间:2023-11-29 11:59:10 25 4
gpt4 key购买 nike

我在 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);

最佳答案

试试这个

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

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

关于mysql - Laravel 查询生成器 - 日期查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32663607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com