Php 在标准时间内减少一个月?

Php 在标准时间内减少一个月?,php,strtotime,Php,Strtotime,全部 在这个循环中,在strottime中减少一个月 $twitter_val7 .='{ date: new Date('.date("Y",strtotime($date)).', '.date("m",strtotime($date)).', '.date("d",strtotime($date)).'), value: '.$result_twitter->counts.

全部

在这个循环中,在strottime中减少一个月

$twitter_val7 .='{
                            date: new Date('.date("Y",strtotime($date)).', '.date("m",strtotime($date)).', '.date("d",strtotime($date)).'),
                            value: '.$result_twitter->counts.'
                            },';

要使用
strotime()
减少1个月,您可以直接告诉它减少1个月:

strtotime($date . ' - 1 month');

当然,假设
$date
是一种格式
strotime()
可以理解。

我会这样做。。我猜
$date
将取代
'2000-01-01'

$initial = new DateTime('2000-01-01');
$interval = new DateInterval('P1M');
$newdate = $initial->sub( $interval );
echo $newdate->format('Y-m-d H:i:s');

使用strotime减少月份

$date='2014-09-03';
$numMonth=1;//here you can pass no. of month
$resultDate=date('Y-m-d',strtotime($date . " - $numMonth month"));

注意这个功能!!!它实际上不是减去1个月,而是减去30天。5月31日将以01结束May@RJD22这不是减法30天。真正的逻辑是1)减少月数。从
2021-03-30
变成
2021-02-30
2),然后因为
2月
最后一天是28日(30和28之间的差是2天)-需要
2021-02-28
加上
2天
现在你有了结果
strotime('2021-03-30-1个月')='2021-03-02'
请先理解这个问题,6票回答问题永远不要错我不是说6票回答错了,但这是另一种减少月收入的方法$numMonth用作动态格式,返回日期用作yyyy-mm-dd格式。