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,
| SitePoint Sponsor |





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,
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy





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
Please don't PM me with questions.
Use the forums, that is what they are here for.





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!)
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy





Will do:
Have a look at this though
http://www.php.net/manual/function.floor.php
Please don't PM me with questions.
Use the forums, that is what they are here for.





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?
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy





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
Please don't PM me with questions.
Use the forums, that is what they are here for.





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?
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy





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.
Please don't PM me with questions.
Use the forums, that is what they are here for.





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!![]()
- Son Nguyen
AdSpeed.com - Ad Serving and Ad Management Made Easy
Bookmarks