Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php where条件下的Laravel日期格式_Php_Laravel_Php Carbon - Fatal编程技术网

Php where条件下的Laravel日期格式

Php where条件下的Laravel日期格式,php,laravel,php-carbon,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',

我有这个密码

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; 
}
选择中的
eodate
字段是datetime。我想把它作为date only放在这个查询中,而不是更改数据库中的字段类型。
有什么想法吗?

如果
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();

但是碳::现在();返回日期和时间,这就是我进行对话的原因。但我的问题是,我想将eodate字段转换为不带时间的日期,因此查询条件会比较mysql中eodate类型为的两个不带时间的日期DATETIME@ElioChamy尝试更新的代码,包括和不包括
toDateString()
whereDate()缺少参数3@ElioChamy第三个参数是可选的
公共函数whereDate($column,$operator,$value=null,$boolean='and')
请再次检查代码是否有错误。我还添加了另一种获取今天数据的方法。