function  DateDiff($d1,$d2=""){  
             if(is_string($d1))$d1=strtotime($d1);  
             if(is_string($d2))$d2=strtotime($d2);  
             return  ($d2-$d1)/86400;  
 }  
function  DateAdd($n,$d=""){  
             if(is_string($d))$d=strtotime($d);  
             return  Date("Y-m-d",$d+$n*86400);  
 }  
echo  DateDiff("2003-09-16","2002-09-27")."<br/>";  
echo  DateAdd(3,"2003-09-16")."<br/>";  
echo  DateAdd(-3)."<br/>";

解决方案 »

  1.   

    <?php
    $todaydate=date("Y-m-d");
    echo $todaydate;//今天的日期
    $threedate=date_add($todaydate,interval 3 day);
    echo "<br>".$threedate//3天后的日期
    ?>
      

  2.   

    就这么个问题还能写出这么千奇百怪的答案出来,还出来个 date_add 函数来,有够搞
    It is possible to use date() and mktime() together to find dates in the future or the past. Example 3. date() and mktime() example <?php
    $tomorrow  = mktime (0,0,0,date("m")  ,date("d")+1,date("Y"));
    $lastmonth = mktime (0,0,0,date("m")-1,date("d"),  date("Y"));
    $nextyear  = mktime (0,0,0,date("m"),  date("d"),  date("Y")+1);
    ?>
     
    http://cn2.php.net/manual/en/function.date.php这个看不明白的别学 PHP 了,当前台文秘什么的可能更适合你
      

  3.   

    TO:platinum(白金)
    你少说一句行不行,打击人家的士气,每个人都是从低学起,不懂就学嘛.
      

  4.   

    其实自己写函数也没什么不好! 只要能作出来就可以!这么一个小东西也没什么效率问题! 我觉得二层的函数只要能说明问题就可以啊!<? 
    //========计算n天以前的日期subolddate()===================== 
    function subolddate($day){ 
    $now=time(); 
    $m=$day*24*60*60; 
    $diff=$now-$m; 
    $oldday=date("Y-m-d",$diff); 
    echo $day."天以前是".$oldday; 

    //======================================================== 
    subolddate(5); 这个函数执行的效率不会比那个差!而且更容易记!