23 May, 2010

Find number of days remain using php

Sometimes it is required to get number of days remaining from some date. Following code is used to calculate
how many days remain from some date using php.

//get number of days remaining from some date
$inpDate = "2010-06-06";
list($inpYear, $inpMonth, $inpDay) = split("[./-]", $inpDate);
$numOfDaysRemaining = ceil((mktime(0,0,0,$inpMonth, $inpDay, $inpYear) - time())/86400);
echo "Num of days remaining:".$numOfDaysRemaining;
//Similarly how many days remain from current date can also be found by setting current date to $inpDate variable
?>

No comments: