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/>";
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/>";
$todaydate=date("Y-m-d");
echo $todaydate;//今天的日期
$threedate=date_add($todaydate,interval 3 day);
echo "<br>".$threedate//3天后的日期
?>
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 了,当前台文秘什么的可能更适合你
你少说一句行不行,打击人家的士气,每个人都是从低学起,不懂就学嘛.
//========计算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); 这个函数执行的效率不会比那个差!而且更容易记!