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

解决方案 »

  1.   

    date_format(tdate,'%Y-%m') = '年-月'年月为你需要的值
      

  2.   

    各位大侠帮帮忙?就是按照where to_days(tdate) = to_days(now())";是得到本日的,那要怎么做才得到本月的?谢谢啊!
      

  3.   

    当月:select ttotal from total_number where month(tdate) = month(now())  
    上月: select ttotal from total_number where month(tdate) = month(date_sub(now(),interval 1 month)) 
      

  4.   

    我这样写对吗?
    $sqlmon="select sum(`ttotal`) as 'ttotal_sum' from total_number where month(tdate) = month(now())";
    $htotalm=mysql_query($sqlsetotal);
    $arrowm=mysql_fetch_assoc($htotaly);
    $ttotalm=$arrowm['ttotal_sum'];
    这样可以可以统计ttotal里面只要是这个月的值吗?
      

  5.   

    我写错啦
    $sqlmon="select sum(`ttotal`) as 'ttotal_sum' from total_number where month(tdate) = month(now())";
    $htotalm=mysql_query($sqlmon);
    $arrowm=mysql_fetch_assoc($htotalm);
    $ttotalm=$arrowm['ttotal_sum'];
      

  6.   

    month(tdate) = month(now()) ???
    去年 8 月的也算??
      

  7.   

    $sqlmon="select sum(`ttotal`) as 'ttotal_sum' from total_number where date_format(tdate,'%Y-%m') = date_format(now(),'%Y-%m')";
    $htotalm=mysql_query($sqlmon);
    $arrowm=mysql_fetch_assoc($htotalm);
    $ttotalm=$arrowm['ttotal_sum'];
    这样写是可以查出2012-08月的来啦,那么2012-07怎么查出来呢?谢谢!
      

  8.   

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