webdevask.com

Menu

  • Home
  • New
  • Add question

how to check if date is 3 months older in php laravel

View Original

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

Source

See also:

  • php สร้าง Google ชีตจากบัญชีบริการ

  • php - Laravel 8.0 Installation Failed

  • javascript - How to include HTML data (tags) as value in "arrayToDataTable" of Google Pie Chart?

  • how to Grouping array in php

  • php - vender folder from my laravel project has more 1k error

© 2021
E-mail: contact@webdevask.com
Back to top