如何在 PHP 中解析日期到上个月的同一天?
例子:
input Output
2018-07-25 -> 2018-06-25
2018-07-31 -> 2018-06-30 (because there is no 31)
Run Code Online (Sandbox Code Playgroud)
我的代码
$d = "2018-07-25";
$xd = date_parse_from_format("y-m-d", $d last month);
$output_d = date_create($xd)->format('Y-m-d');
Run Code Online (Sandbox Code Playgroud)