I am using this:
$dateBetween = date("z",time()) - date("z",$inputTime);
Although I know there will be the problem at the end of a year (1st date will be smaller than the 2nd one).
So how could we get around in this situation?
Great thanks,
Printable View
I am using this:
$dateBetween = date("z",time()) - date("z",$inputTime);
Although I know there will be the problem at the end of a year (1st date will be smaller than the 2nd one).
So how could we get around in this situation?
Great thanks,
Try this:
//Subtract the two timestamps
$time = time() - $inputtime;
//Divide by the number of seconds in a day and round off
$numdays = number_format(($time / 86400), 0);
print $numdays
True. I've thought about that before, but I remember I used floor(). I'll test it again.
Thanks Freddy! (i also have another question about timing, please take a look at it!)
Will do:
Have a look at this though
http://www.php.net/manual/function.floor.php
Yes, php.net is my main/wonderful source of getting reference.
So using number_format($somefraction,0) is the same thing as floor($somefraction), am I right?
number_format will round off correctly so 1.7 would be 2 I think floor takes the lower end always. 1.7 would be 1
Oh, if number_format() does round up (which I believe it is), then I think the code you provided:
$numdays = number_format(($time / 86400), 0);
will have problem:
Test case: $time / 86400 = 0.6 -> returns 1 day -> not today, but yesterday! And the correct return value should be 0.
So the floor should be correct?
I guess that would be a matter of prefernece, if it was half way through the day alreay I would count the day, if not I wouldn't.
True, since I want to check for the last 7 days, 0-6 will be returned (in compare with today), so I believe using floor will do. Thanks for the discussion! :)