Search code examples
php-carbon

Next Augustus in Future with Carbon


Is there prettier way to get the full-date of the next 1st of August:

$year = date('Y') + 1;
if (date('j') >= 1 && date('j') <= 8) {
    $year = date('Y');
}
$nextAugust = '01-08-' . $year;
$nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);

Preferably with Carbon PHP


Solution

  • Following code find next august with carbon object.

    $nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));
    

    I hope my answer can help for your problem.