2016-02-10 85 views
2

如果现在是2016年2月10日 我需要返回2015年7月1日(或2015年7月10日)php:strtotime如何获得去年7月? (或其他特定月)

strtotime('july'); // returns 2016-07-10 
strtotime('last july'); // does not work 
strtotime('july 2015'); // I have not '2015' for query. 
//Only if compare date (month) now and month needed. In looks not realy straight way. 

回答

2

如果你是过去的今年七月份会发生什么?那么它是否需要在2016年7月回归,还是总是在前一年?

如果是这样,你可以使用“去年七月”:

<?php 
$returnValue = strtotime('july last year'); 

根据需要回到今年7月份还有:

<?php 
$returnValue = strtotime('july '. (date("n") >= 7 ? 'this' : 'last') .' year'); 
+0

是的,如果我过去的七月或者在中间的,那么2016年7月就需要 – scrache

+0

根据这个要求进行了更新。 –

+0

对不起,我认为一个同事不小心点击投票,我没有意识到,所以我不能撤消。这实际上很有帮助谢谢! – superjaz1

相关问题