Maison  >  Article  >  développement back-end  >  php 本月、下月时间

php 本月、下月时间

WBOY
WBOYoriginal
2016-06-13 13:16:091259parcourir

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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent: XML的异常在哪里啊 Article suivant: 下传图片的有关问题