Laravel Eloquent Select Between current month and previous 3 months -


i'm trying build query select of records in db between (current month) , previous 3 months.

my query works, want ignore day of month. @ moment, it's selecting last # of months current day want ignore current day , use start , end of months.

here's 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 appreciated. it's bugging me!

this trick guess

$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() begins 1st date of month


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -