[英]PHP - Get previous month name from current month
$_POST['month_year'] = APR-2015
$mth = "April";
$pre_mth = Date("F", strtotime($mth . " last month"));
$pre_mth
gives me only month name which is 'March'. $pre_mth
仅给我一个月名,即“ March”。
How can I fetch previous month-year in the format MAR-2015
? 我如何以
MAR-2015
格式获取上个月的年份?
$input = 'APR-2015';
$dt = new DateTime($input);
$dt->modify('last month');
$output = $dt->format('M-Y');
echo strtoupper($output);
// Output:
// MAR-2015
You can use the php function strtotime() , ie: 您可以使用php函数strtotime() ,即:
$post = "APR-2015";
echo strtoupper(date('M-Y', strtotime($post. "-1 Month")));
Output: 输出:
MAR-2015
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.