2015-01-21 71 views
-1

例如,日期是21/01/2015 我想得到22/02/2015(下个月的日期从21日增加到22日)如何获得下个月的日期+1从今天开始php

我是如何实现这一目标的? 我正在使用strtotime('+ 1 month'); 输出: - 21/02/2015 ..而这只会让我下个月与现在的日期,即21

+2

你期望得到的1月30日? – 2015-01-21 09:26:06

+2

'strtotime(' - 1 month');'你会得到'21/02/2015'?逻辑在哪里? – Rizier123 2015-01-21 09:26:54

+3

请注意,要获得___next___个月,通常会执行“+1个月”,而不是“-1个月”。 – 2015-01-21 09:27:06

回答

2

嗯,我想

strtotime('-1 day', strtotime('-1 month')) 

或者,如果你确实需要下一个月,而不是以前的一个,然后

strtotime('+1 day', strtotime('+1 month')) 

这将有有趣的文物,如果相应天数不存在(例如,如果你把它在1月31日),但我想不清楚在这种情况下该怎么做。

1

以下尝试: -

$end_date = mktime(0,0,0,date('m')+1,date('d')+1,date('Y')); 

echo date('Y-m-d', $end_date); 
+0

这对我有用..谢谢 – user2971353 2015-01-21 09:35:53

+0

高兴地帮助你 – Khushboo 2015-01-21 09:36:21

+0

它在12月工作吗? – 2015-01-22 00:48:20

-2

我会送你

$day = date('d'); 
$month = date('m')+1; 
$year = date('Y'); 
$nextDay = $day+1; 
$nextMonth = $month + 1; 
echo $nextDate = $nextDay.'/'.$nextMonth.'/'.$year; 
+2

这是一个问答网站,而不是论坛,如果答案没有帮助,请避免使用“你好”和“谢谢”。阅读指南以了解如何改进您的答案,并使用文本格式化来澄清您的帖子,以免使其更明显 – jean 2015-01-21 10:15:07

+1

12月31日会发生什么? nextMonth是'13',nextDay是'32'? – 2015-01-21 10:38:16