我试着把一个月的日期从一个日期倒转到给定的日期。我编写的代码做了减法,但我不知道它为什么不完成循环。下面是代码块
$date7 = date('Y-m-10');
$lastsaving = date("2013-2-9");
while($lastsaving < $date7){
$newdate = strtotime ( '-1 month' , strtotime ( $date7 ) ) ;
$date7 = date ( 'Y-m-d' , $newdate );
echo $date7;
echo "<br />";
} 我得到的是
2015-05-10
2015-04-10
2015-03-10
2015-02-10
2015-01-10
2014-12-10
2014-11-10
2014-10-10
2014-09-10
2014-08-10
2014-07-10
2014-06-10
2014-05-10
2014-04-10
2014-03-10
2014-02-10
2014-01-10
2013-12-10 请帮我找出它没有完成循环的原因
发布于 2015-06-04 08:17:22
变化
$lastsaving = date("2013-2-9"); 至
$lastsaving = date("2013-02-9"); 在这里,您可以看到工作的一个:http://codepad.org/uI0R6TvC
我上面的那个人也是对的:)这也是可行的。
while(strtotime($lastsaving) < strtotime($date7)) { 在这里测试:http://codepad.org/OY36ij3U
发布于 2015-06-04 08:17:22
为此,您必须首先将它们转换为时间戳,用于comparing.Use strtotime() -
while(strtotime($lastsaving) < strtotime($date7)) { ... // rest of the code发布于 2015-06-04 08:39:00
我按照上面@Danyal的建议将$lastsaving = date("2013-2-9");改为$lastsaving = date("2013-02-09");
https://stackoverflow.com/questions/30638425
复制相似问题