3v4l.org

run code in 200+ PHP versions simultaneously
<?php $date_object = new DateTime('2011-04-24'); echo "Today: ".date('Y-m-d').PHP_EOL. "Yesterday: ".date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")-1, date("Y"))).PHP_EOL. "42 days ago: ".date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")-42, date("Y"))).PHP_EOL. "OP's date: ".date('Y-m-d', mktime(0, 0, 0, $date_object->format("m"), $date_object->format("d")-1, $date_object->format("Y") ) );
based on 4PD2e
Output for 5.6.38 - 7.4.1
Today: 2019-08-13 Yesterday: 2019-08-12 42 days ago: 2019-07-02 OP's date: 2011-04-23