One-liner option:
echo date_create('2011-04-24')->modify('-1 days')->format('Ym-d');
Running it in the online PHP editor .
If you prefer to avoid using string methods, going to calculations, or even creating additional variables, mktime supports subtraction and negative values ββas follows:
// Today date echo date('Ym-d'); // 2016-03-22 // Yesterday date echo date('Ym-d', mktime(0, 0, 0, date("m"), date("d")-1, date("Y"))); // 2016-03-21 // 42 days ago echo date('Ym-d', mktime(0, 0, 0, date("m"), date("d")-42, date("Y"))); // 2016-02-09 //Using a previous date object $date_object = new DateTime('2011-04-24'); echo date('Ym-d', mktime(0, 0, 0, $date_object->format("m"), $date_object->format("d")-1, $date_object->format("Y") ) ); // 2011-04-23
PHP online editor
Armfoot Mar 22 '16 at 12:37 2016-03-22 12:37
source share