how to check if date is 3 months older in php laravel
Solution:
You can use to achive this:
$start_date = new Carbon\Carbon('2021-03-04');
if($start_date->diffInMonths() > 3)
{
}
Answer
Solution:
You need something similar to:
$format = "y-m-d";
$start_date = \DateTime::createFromFormat($format, $start_date);
$end_date = \DateTime::createFromFormat($format, $start_date);
$end_date = $end_date->modify('+3 month');
if($start_date < $end_date)
{
}
I haven't tested the code, but you can get an idea.
Answer
Solution:
You can use this :
$start_date = '2021-03-04';
if($start_date < date('Y-m-d', strtotime('-3 months'))){
}
Answer
Solution:
You can use Carbon for that.
// parse your date as carbon date & only take the date string using toDateString
$start_date = Carbon::parse('2021-03-04')->toDateString();
// take the Today time, subtract 3 months from it & only take date string from it
$today = Carbon::today()->subMonths(3)->toDateString();
if ($start_date < $today) {
// whatever you wanna do here
}
Note: Carbon adds timestamp so using toDateString() you ignore that timestamp & only factor in the date string