$today = new DateTime(); $today->sub(new DateInterval('P1D')); echo $today->format('Y-m-d');
$date = new DateTime('2022-07-01 09:45:00'); $date->sub(new DateInterval('PT1H30M')); echo $date->format('Y-m-d H:i:s');
use Carbon\Carbon; $date = Carbon::create(2022, 7, 15); $date->subWeeks(2)->subDays(6); echo $date->format('Y-m-d');This code will output the date of June 26, 2022, in the format 'Y-m-d'. The package library used in this example is the Carbon library, a popular extension of PHP DateTime class that provides additional methods for working with dates and times.