<?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")
)
);
- Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
- Today: 2022-11-17
Yesterday: 2022-11-16
42 days ago: 2022-10-06
OP's date: 2011-04-23
preferences:
81.92 ms | 408 KiB | 5 Q