算法错了,比如$today=20061121,$thattime=2006-10-11
$today - $thattime = 20061121 - 20061011 = 110
显然,20061011并不是110天前.楼主加油,万事开头难.

解决方案 »

  1.   

    是不是可以这样算:
    $today = $time;
    $thattime = mktime(0,0,0,$b,$c,$a);
    $hiday = ($today - $thattime) / 60 /60 /24;
      

  2.   

    其实用php里面自带的函数就可以实现的,如果是急着应用的话,应该先好好查查手册,不然是很耽误时间的,如果是当作算法锻炼也不错。我以前也干过类似的事。加油
      

  3.   

    刚开始不是紧,好好学习,总会进步的
      $lastday = mktime (0,0,0,$b,$c,$a);  $subday=round((time()-$lastday)/3600/24); echo " 吼吼,偶学习php ".$subday." 天了";
      

  4.   

    首先, 在转化Uniux时间戳时, 不要再自己写了.PHP提供现成的函数strtotime()以下三行可以写为:  $today = date('Ymd'); $thatday = strtotime($thattime);$today = date('Ymd');
    list($a,$b,$c) = explode('-',substr($thattime,0,10));
    $thatday = $a.$b.$c;其次, elseif太多了,影响程序效率.
    建议使用switch($hiday){}
      

  5.   

    祝贺你,加油:
    btw:
    list($a,$b,$c) = explode('-',substr($thattime,0,10));
    $thatday = $a.$b.$c;can change to:
    $thatday = str_replace('-','',substr($thattime,0,10));
      

  6.   

    抱歉,前面我把time()写成$time了.
      

  7.   

    $thatday = date('Ymd',strtotime($thattime));另外,也可以用date('z')来做运算,只是还需要判断一下年数