当前位置:Gxlcms > PHP教程 > php本月、下月时间

php本月、下月时间

时间:2021-07-01 10:21:17 帮助过:2人阅读

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")

人气教程排行