Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Make array from_date to to_date using CarbonPeriod and Match another date is exist in array or not in php , Laravel

i have two date :
$from = 2022-11-01
$to = 2022-11-05

now , i wanna create a array like this :
$date = [‘2022-11-01′,’2022-11-02′,’2022-11-03′,’2022-11-04′,’2022-11-05’]

and now check ‘2022-11-03’ is exist in $date array or not.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

alrady use :
$date = Carbon\CarbonPeriod::create($from, $to);

if(in_array('2022-11-03', $date)){
    echo "Got it";
}

#But Still not Work

>Solution :

You can just check if the CarbonPeriod contains the date you check:

$from = '2022-11-01';
$to = '2022-11-05';
$date = Carbon\CarbonPeriod::create($from, $to);
if ($date->contains('2022-11-03')) {
    echo 'Got it';
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading