Laravel where条件下的日期格式

Laravel date format in where condition

我有这个代码

use Carbon;
$now = Carbon::now()->toDateString(); 

所以我得到没有时间的日期

public funtion test($brandid){

     $nbofsale=DB::table('st_nsales')
                         ->where('brand_id', $brandid)
                         ->where('eodate', $now)
                         ->get();
     return $nbofsale; 
}

select 中的 eodate 字段是日期时间。我只想将它作为日期放入此查询中,而不是更改数据库中的字段类型。 有什么想法吗?

如果eodate是时间戳,则不需要将其转换为日期字符串:

$nbofsale = DB::table('st_nsales')
              ->where('brand_id', $brandid)
              ->whereDate('eodata', Carbon::today()->toDateString());
              ->get();

获取今天记录的另一种方式:

$nbofsale = DB::table('st_nsales')
              ->where('brand_id', $brandid)
              ->where('eodata', '>', Carbon::now()->startOfDay());
              ->get();