I am creating a value that shows me the remaining time from a date until now:
$date=date_create(date('Y-m-d H:i:s', strtotime($mydate)));
$curdate=date_create(date("Y-m-d H:i:s"));
$diff=date_diff($date,$curdate);
$diff1= $diff->format("%y years %m months %d days");
The result in this case is: 0 years 0 months 27 days
What I would like to do is, show only years
or months
if they are not 0
. So in this case I would only like to get the result 27 days
. And if it is only one day left, then it shows 1 days
but it should show 1 day
(so if the result is 1
show singular).
I tried something like this, but it didn't work:
$diff1= $diff->format(if("%y" !=0){"%y years"}); if("%m" !=0){"%m months"}) %d days");