php日期都是用时间戳来计算的。所以会出现这个问题。
解决方案 »
- php中的sql语句where条件中假如有变量应该怎么办?
- 站点里的奇怪问题????
- PHP中如何禁止重复刷新页面
- 当前PHP页面中,执行其他页面程序并返回程序值
- 出现错误 Parse error: parse error, unexpected T_PUBLIC
- PHP怎么连接SQL Server?
- 高人请入!急!
- htmlentities跟htmlspecialchars没有反函数的吗?
- phplib模板中调用require后怎样把require中输出的内容定位?
- 怎么让两个不同的国际域名指向同一个服务器上的不同目录(apache做服务器软件)
- SQL查询问题
- 关于php网站根目录外连接文件的一个问题
对,这个bug已经存在很长时间了,具体可以到官网上去查.
但官方认为这不是BUG,建议用date("Y.m",strtotime("-31 days"))来替代.
要不就直接计算天数,减天数来做.
$j=$i*31;
date("Y.m",strtotime("-"."$j"."days"));
如果是月份数大了,比如说递减的月份到几年前了,哪要是按每月31天减也会产生误差吧,不到3年的周期会差出一个月吧。
直接用mysql的日期函数来做,可能会更好些.
比如说你想取08年的,哪就匹配一下 2008-xx的串吗,
mysql支持unix时间戳的操作.
这样比你事先构造串不是更好一些. 如果你非得想得到,也可以用select distinct()来实现呀.多一部查询而矣.
文字串转换时间不精确
select distinct(DATE_FORMAT('时间字段', '%Y%m')) FROM 表名
?>will cause troubles when calculating the relative time. It often is one day or even one month off... After I set the time to noon "strtotime" calculates as expected.Also taken from there:Just pointing out that date( 'M', strtotime( 'last month', [some timestamp]) ) will not actually give the name of the previous month if the day of [some timestamp] doesn't exsist in the previous month. It will instead round up, and give the name of one month AFTER the previous month ('this month', that is).For example date( 'M', strtotime( 'last month', [March 31st]) ) will return 'Mar'.This is documented here: http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html (also linked from this manual page), but is not easy to find:" The fuzz in units can cause problems with relative items. For example, `2003-07-31 -1 month' might evaluate to 2003-07-01, because 2003-06-31 is an invalid date. To determine the previous month more reliably, you can ask for the month before the 15th of the current month. For example:$ date -R
Thu, 31 Jul 2003 13:02:39 -0700
$ date --date='-1 month' +'Last month was %B?'
Last month was July?
$ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!'
Last month was June! "What you can do is do it manually:<?php
$month = 31 * 24 * 60 * 60; //not exactly last month, but 31 days earlier.
// 31 days; 24 hours; 60 minutes; 60 seconds
$lastMonth = date('Y-m-d', time() - $month);
?>