Laravel日期格式在哪里条件

时间:2017-01-30 11:57:27

标签: php laravel php-carbon

我有这段代码

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。我想将它作为日期放在此查询中,而不是更改数据库中的字段类型。 有什么想法吗?

1 个答案:

答案 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();