添加特定月份的记录
add records from a particular month
我需要添加 7 月份的记录。
我的代码:现在只能添加当月的记录
$cobrosm = Cobros::whereBetween('created_at',[
$carbon->startOfMonth()->toDateString(),
$carbon->endOfMonth()->toDateString()
])->sum('importe');
尝试使用此代码:
$julyDate = date('Y-07-d');
$cobrosm = Cobros::whereBetween('created_at',[
Carbon::createFromFormat('Y-m-d', $julyDate)
->firstOfMonth()
->toDateString(),
Carbon::createFromFormat('Y-m-d', $julyDate)
->lastOfMonth()
->toDateString()
])->sum('importe');
有关 Carbon 的更多信息 https://carbon.nesbot.com/docs/
我需要添加 7 月份的记录。
我的代码:现在只能添加当月的记录
$cobrosm = Cobros::whereBetween('created_at',[
$carbon->startOfMonth()->toDateString(),
$carbon->endOfMonth()->toDateString()
])->sum('importe');
尝试使用此代码:
$julyDate = date('Y-07-d');
$cobrosm = Cobros::whereBetween('created_at',[
Carbon::createFromFormat('Y-m-d', $julyDate)
->firstOfMonth()
->toDateString(),
Carbon::createFromFormat('Y-m-d', $julyDate)
->lastOfMonth()
->toDateString()
])->sum('importe');
有关 Carbon 的更多信息 https://carbon.nesbot.com/docs/