我正在尝试构建一个查询,该查询将选择数据库中现在(当月)和前 3 个月之间的所有记录。
我的查询有些有效,但我想忽略该月的某一天。目前,它也选择当前日期的最后几个月,但我想忽略当前日期并使用月份的开始和结束。
这是我的查询:
$dateS = Carbon::now()->subMonth(3);
$dateE = Carbon::now();
$TotalSpent = DB::table('orders')
->select('total_cost','placed_at')
->whereBetween('placed_at',[$dateS,$dateE])
->where(['deleted' => '0', 'delivery_address_id' => $DeliveryAddress->id])
->sum('total_cost');
任何帮助,将不胜感激。真是烦死我了!
我想这会起作用
$dateS = Carbon::now()->startOfMonth()->subMonth(3);
$dateE = Carbon::now()->startOfMonth();
$TotalSpent = DB::table('orders')
->select('total_cost','placed_at')
->whereBetween('placed_at',[$dateS,$dateE])
->where(['deleted' => '0', 'delivery_address_id' => $DeliveryAddress->id])
->sum('total_cost');
startOfMonth()
从该月的第一天开始
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)