简体   繁体   中英

Minus one month off of date

$_month is set to 05. I want to minus one month off of it.

I am using the following:

$newdate = strtotime ( '-1 months' , $_month ) ;
            $newdate = date ( 'm' , $newdate );
            echo $newdate;

However, my result is coming out at 12.

What am I doing wrong, when it should be 04?

Solved after many attempts, this will give me the flexibility that I need.

$pDate = strtotime('1-'.$_month.'-2017 - 1 month');
echo date('m',$pDate);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM