如果我有一个日期等于: 2020-04-21
我想把这一天: 21
以本月为例:12月
算一算,好像是12月:2020年-12-21
并将其转换为前一个月,保持日复一日,然后: 2020-11-21
我该怎么做?
发布于 2020-12-21 11:45:56
<?
$time=strtotime('2020-04-21'); // get unixtime of custom date
$day=date('d', $time); // get day of custom date
$year=date('Y', $time); // get year of custom date
$month=date('m'); // get current month
$time_first=mktime(0, 0, 0, $month, $day, $year); // get unixtime for first
$time_second=strtotime('-1 month', $time_first); // get unixtime previous month
$date_first=date('Y-m-d', $time_first); // string format of first date
$date_second=date('Y-m-d', $time_second); // string format of second date
var_dump($date_first);
var_dump($date_second);
?>
https://stackoverflow.com/questions/65391961
复制相似问题