mardi 12 septembre 2017

Laravel Eloquent Select Between current month and previous 3 months

i'm trying to build a query that will select all of the records in my DB between now (current month) and the previous 3 months.

My query somewhat works, but i want to ignore the day of the month. At the moment, it's selecting the last # of months to the current DAY as well but i want to ignore the current day and use the start and end of the months.

Here's my query:

$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');

Any help would be appreciated. It's really bugging me!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire