0

How to calculate the amount between 2 dates. For example Consider if in month January 2021 I need to get the amount between From Date: 1st Jan 2021 and To Date : `15 Jan 2021. The calculation should be = Total Amount - (Amount from 16 Jan to 31 Jan)

Hope for a guidance to solve this :)

2

2 Answers 2

0

Use whereBetween... Try:

$date1 = date('2021-01-01');
$date2 = date('2021-01-15');
    
Your_Model::whereBetween('date_col', [$date1, $date2])
    ->select( DB::raw('SUM(your_col) as amount'))
    ->get();
Sign up to request clarification or add additional context in comments.

Comments

0
$date1 = 1st Jan 2021 //formate upto you, standard format 2021-01-01
$date2 = 15 Jan 2021 //formate upto you, standard format 2021-01-15

$total_amount = $date1->diff($date2);

Or follow this,

Finding days between two dates in laravel

I hope it will be work!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.