Home › Forums › Back End › Countdown with php ? › Re: Countdown with php ?
May 31, 2011 at 1:48 am
#74940
ddliu
Member
Sorry I don’t quite understand what is your problem.
Can you get expiration information from database?
Can you calculate how long(e.g. how many days) will it expire?
Do you have problem displaying it in the web page?
Anyway, I can show you a function might be helpful: https://gist.github.com/1000031
function getDateDiff($date)
{
$diff_info=array();
$timestamp=strtotime($date);
$timestamp_diff=$timestamp-time();
//test if $date is future
$diff_info=$timestamp_diff>0;
$timestamp_diff=abs($timestamp_diff);
//calculate total date difference
$date_diff=round($timestamp_diff/(24*3600));
//year
$diff_info=floor($date_diff/365);
$date_diff-=$diff_info*365;
//month
$diff_info=floor($date_diff/30.5);
$date_diff-=floor($diff_info*30.5);
//day
$diff_info=$date_diff;
return $diff_info;
}
and how to use it:
$diff=getDateDiff('8/12/2012');
if($diff)
{
echo "You have {$diff} year(s), {$diff} month(s), {$diff} day(s) left";
}
else
{
echo "Your account has expired";
}