我试过了:
$firstOfMonth = "2015-01-01";
$last_month = date("Y-m-d", strtotime('first day of -1 month', strtotime($firstOfMonth)));
/* ^^^^^ This gives me 01 of last month */
/*** Tried 'seventh day of -1 month'
/* it gives 1970-01-01
*/
我想要的是获得上个月的07。
答案 0 :(得分:2)
$firstOfMonth = "2015-01-01";
$last_month = date("Y-m-01",strtotime("-1 month",strtotime($firstOfMonth)));
答案 1 :(得分:0)
就像曼哈顿先生说的那样,你只需要年份和月份,到第七天你可以将其保留为硬编码或变量:
date("Y-m-07",strtotime("-1 month"));
$fixedDay = '07';
echo date("Y-m-$fixedDay",strtotime("-1 month"));