Home >Backend Development >PHP Tutorial > php 本月、下月时间

php 本月、下月时间

WBOY
WBOYOriginal
2016-06-13 13:16:091330browse

php 本月、上月时间
这种可以得到本日的时间
$sqljrfw="select ttotal from total_number where to_days(tdate) = to_days(now())";
这个tdate是一个时间字段类型是2012-08-16这种类型,那么我怎么才能得到这个08月的所有数据呢?还有08月的上一个月的数据?

------解决方案--------------------
date_format(tdate,'%Y-%m') = '年-月'

年月为你需要的值
------解决方案--------------------
sorry,搞错了,忘记考虑年份了。改成下面试试:
当月:select ttotal from total_number where date_format(tdate,"%Y-%m") = date_format(now(),"%Y-%m")
上月: select ttotal from total_number where date_format(tdate,"%Y-%m") = date_format(date_sub(now(),interval 1 month),"%Y-%m")

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