php - Day count - calculation and remove the minus
153
From the calculation returns -30. How can I remove the minus, so it just returns 30
$days = (strtotime(date("Y-m-d")) - strtotime($info['expiredate'])) / (60 * 60 * 24)
echo $days
What is the best approach?
Answer
Solution:
So long as you are sure the calculation is always in the right order, you can just use the
abs()
function to always display the positive number.Answer
Solution:
In mathematics
x-y == -(y-x)
... Flip the order of subtraction.