I want to get the difference time between Now and today midnight but I get a negative number. Why?
echo strtotime('today midnight') - strtotime("now");
I want to get the difference time between Now and today midnight but I get a negative number. Why?
echo strtotime('today midnight') - strtotime("now");
As mentioned in ceeyajoz's comment, midnight is relatively unclear, see this reference link.
As for your question, consider this eval.in script.
Yesterday midnight is not the same as today midnight, which is sooner than now. It seems that midnight
means the midnight that happened at the beginning of the present day. Considering that, it's understandable that you get a negative integer, since midnight already happened.
As mentioned in yet another useful comment:
@user3066977 If you want the time left until midnight, do
strtotime('tomorrow midnight') - time()
orstrtotime('tomorrow 00:00:00') - time()