SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •