php if statement - time/date/strtotime related
I am using the following code to calculate the days remaining to make edits. They have 30 days to make edits, and days count down, this code wor开发者_开发问答ks perfectly.
<?php
// Calculate days remains to edit or change details
$today = time();
$cdate = strtotime($row_details['payment_date']);//strtotime("19:19:09 Sep 27, 2011");
$dateDiff = $today - $cdate;
$fullDays = floor($dateDiff/(60*60*24));
$dayscalculate = 30 - $fullDays; // Set number of days
echo $dayscalculate.(($dayscalculate == 1) ? " day" : " days");
//
?>
QUESTION: if days = say 3 will say 3 days.. but if days = 0 (is the last of the 30 days).. Then want to say this is your last day or something.. So need an if based on $dayscalculate..
Ideas?
Thank you
How about...
if ($dayscalculate == 0) {
echo 'This is your last day';
} else {
printf('%d day%s',
$dayscalculate,
$dayscalculate > 1 ? 's' : ''
);
}
You may also want to introduce an "out of time" check, ie $dayscalculate < 0
but then again, you may already be handling this scenario.
精彩评论