Just convert both units to unix timestamp, make your subtraction, then divide it by 86400:
$expiry_date = '2016-04-18';
$today = time();
$interval = strtotime($expiry_date) - $today;
$days = floor($interval / 86400); // 1 day
if($days < 7) {
echo 'less';
}
Or another way with DateTime
classes:
$expiry_date = '2016-04-18';
$expiry_date = new DateTime($expiry_date);
$today = new DateTime();
$interval = $today->diff($expiry_date);
$day = $interval->format('%r%a');
if($day < 7) {
echo 'less';
}
Example conditions:
$expiry_date = '2016-04-18';
$today = time();
$interval = strtotime($expiry_date) - $today;
$day = floor($interval / 86400); // 1 day
if($day >= 1 && $day < 7) {
echo 'between 1 - 7 days';
} elseif($day <= 0) {
echo 'deadline';
} else {
echo 'soon';
}
Just change / tweak it depending on what you're trying to do.