Saturday, May 24, 2008

Calculating difference between two dates using PHP

If you want to get the difference between to dates use this script:
Example:

<?


$date1 = date("Y/m/d");

$date2 = date("Y/m/d");


echo datediff($date1, date2);


function datediff($sdate,$edate){

$rs = $this->execute("select to_days('$edate') - to_days('$sdate') as diff");

if($row = $this->row($rs)){

return $row["diff"];

}else{

return "0";

}

}


?>

No comments: