Home >Backend Development >PHP Tutorial > php计算月度间距

php计算月度间距

WBOY
WBOYOriginal
2016-06-13 12:55:16882browse

php计算月份间距
比如这个月是9月份
要计算从前至去年9月份,至下4个月(要考虑到跨年的情况),的每一个月的时间戳
即2011.9-2013.1
分数不多都给了,结贴及时,谢谢大家!


------解决方案--------------------
WHERE date  ".strtotime('-12 month')."
------解决方案--------------------
$t = date('Y-m-01'); //不能直接使用当前时间,否则月底会出问题<br />
for($i=-12; $i<=4; $i++) {<br />
  echo date('Y.m', strtotime("$i month $t")), PHP_EOL;<br />
}
2011.09
2011.10
2011.11
2011.12
2012.01
2012.02
2012.03
2012.04
2012.05
2012.06
2012.07
2012.08
2012.09
2012.10
2012.11
2012.12
2013.01
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn