In the list page, i want to display time left along with the expiry_date field.
Go to List page, add a custom value to the expiry_date as follows:
// if the expiry_date is future date, show how number of Day, Hours, Minutes and seconds left.
if ($value > NOW())
{
$firstTime=strtotime($value);
$lastTime=strtotime(NOW());
// perform subtraction to get the difference (in seconds) between times
$diff=$firstTime-$lastTime;
// convert
$years = floor($diff / (365606024));
$months = floor(($diff - $years 365606024) / (30606024));
$days = floor(($diff - $years 365606024 - $months30606024)/ (606024));
$hours = floor(($diff - $years 365606024 - $months30606024 - $days606024)/ (6060));
$minutes = floor(($diff - $years 365606024 - $months30606024 - $days606024 - $hours6060)/ 60);
$seconds = floor(($diff - $years 365606024 - $months30606024 - $days606024 - $hours6060 - $minutes*60));
//
$time_left = "";
if ($years > 0 ) { $time_left .= $years."Y ";}
if ($days > 0 ) { $time_left .= $days."D ";}
if ($hours > 0 ) { $time_left .= $hours."H ";}
if ($minutes > 0 ) { $time_left .= $minutes."M ";}
if ($seconds > 0 ) { $time_left .= $seconds."S";}
$value .= "<br/><STRONG><FONT COLOR='orange'>Expires in<br/>";
$value .= $time_left;
$value .= "</STRONG></FONT>";
}
else
{
// Show an Expired message below the date in red.
$value .= "<br/><font color='red'>Expired</font>";
}