Monday, November 17, 2008

Add Days to a Date

DATE Function in PHP - ADD DAYS
By using this function you can easily Add days into date and as well as subtract days from date.

//Example
$date = "2008-11-10";
$fdate = adddays($date,5);
echo fdate; //result : 2008-11-15

$date = "2008-11-10";
$fdate = adddays($date,-5);
echo fdate; //result : 2008-11-05


function adddays($date,$days){
$rs = $this->execute("select DATE_FORMAT(DATE_ADD('$date',INTERVAL $days DAY),'%Y-%m-%d') as newdate");
if($row = $this->row($rs)){
return $row["newdate"];
}else{
return "0000-00-00";
}
}
?>

No comments: