要取和时间差,在SQL语句里就可以了呀
你的函数有很多问题:
1)if($year1[1]<$year2[1])
        {
              $max_x=$max_x+($year2[1]-$year1[1])*30;
         }
    else{
              $max_x=$max_x+($year2[2]-$year1[2]);
        }
根本就没有必要,由于是代数和,所以不用判断year[1],year[2]的大小。
2)难道一个月只有30天?二月怎么办?大月又怎么办?
直接一点:
$SQL = "select to_days(curdate())-to_days(pudate) as days from tablename where XXXX";
over!

解决方案 »

  1.   

    字符串格式的日期?
    $s = strtotime($time1)-strtotime($time2);
    得到两个日期的差,单位是秒。
      

  2.   

    mysql的to_Days啊
    找本MySQL中文手册看看日期和时间函数部分吧
    会有你想要的东东
      

  3.   

    $date1="2003-7-17";//数据库取得
    $date2="2003-7-1";//手工$sql="select to_days(".$date1.")-to_days(".$date2.") as datediff";
    $q=mysql_query($sql);
    $DateDiff=mysql_result($q,0);
    echo$DateDiff;