Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts

    simple question with time() manipulation

    i have a bunch of logged time() values from around a week ago, and i want to calculate the difference between time() and that value like this:

    PHP Code:
    $diff time() - $pasttime
    the dilemma i am having with this is how to calculate how many days, hours, mins and seconds this difference is. help appreciated, this is reasonably urgent.

    if you don't understand what i mean, i mean turning the difference which may be like 550392 (seconds) into something like 7 days, 3 hours, 28 mins, 51 secs.

  • #2
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    PHP Code:
    <?php
    function countdown ($count) {
    $difference $count time();
    $abs_difference abs($difference);

    $days floor($abs_difference/60/60/24);
    $hours floor(($abs_difference $days*60*60*24)/60/60); 
    $minutes floor(($abs_difference $days*60*60*24 $hours*60*60)/60);

    if (
    $difference != $abs_difference) {
    return 
    "It was $days days, $hours hours and $minutes minutes ago!";
    } else {
    return 
    "Only $days days, $hours hours and $minutes minutes to go!";
    }

    }
    ?>
    Should be simple enough to modify.

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks alot for that


  •  

    Posting Permissions

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