我有这段代码
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
字段是datetime。我想将它作为日期放在此查询中,而不是更改数据库中的字段类型。
有什么想法吗?
答案 0 :(得分:1)
如果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();