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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    how many minutes

    hi all,

    im trying to work out how many minutes have past and how many remain since the last datetime stamp...

    does anyone know of any pre-existing functions for this before I reivent the wheel?

    Many thanks

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    This is from this website: http://us2.php.net/time

    PHP Code:
    <?php
    define
    ('INT_SECOND'1);
    define('INT_MINUTE'60);
    define('INT_HOUR'3600);
    define('INT_DAY'86400);
    define('INT_WEEK'604800);

    function 
    get_formatted_timediff($then$now false)
    {
        
    $now      = (!$now) ? time() : $now;
        
    $timediff = ($now $then);
        
    $weeks    = (int) intval($timediff INT_WEEK);
        
    $timediff = (int) intval($timediff - (INT_WEEK $weeks));
        
    $days     = (int) intval($timediff INT_DAY);
        
    $timediff = (int) intval($timediff - (INT_DAY $days));
        
    $hours    = (int) intval($timediff INT_HOUR);
        
    $timediff = (int) intval($timediff - (INT_HOUR $hours));
        
    $mins     = (int) intval($timediff INT_MINUTE);
        
    $timediff = (int) intval($timediff - (INT_MINUTE $mins));
        
    $sec      = (int) intval($timediff INT_SECOND);
        
    $timediff = (int) intval($timediff - ($sec INT_SECOND));

        
    $str '';
        if ( 
    $weeks )
        {
            
    $str .= intval($weeks);
            
    $str .= ($weeks 1) ? ' weeks' ' week';
        }

        if ( 
    $days )
        {
            
    $str .= ($str) ? ', ' '';
            
    $str .= intval($days);
            
    $str .= ($days 1) ? ' days' ' day';
        }

        if ( 
    $hours )
        {
            
    $str .= ($str) ? ', ' '';
            
    $str .= intval($hours);
            
    $str .= ($hours 1) ? ' hours' ' hour';
        }

        if ( 
    $mins )
        {
            
    $str .= ($str) ? ', ' '';
            
    $str .= intval($mins);
            
    $str .= ($mins 1) ? ' minutes' ' minute';
        }

        if ( 
    $sec )
        {
            
    $str .= ($str) ? ', ' '';
            
    $str .= intval($sec);
            
    $str .= ($sec 1) ? ' seconds' ' second';
        }
       
        if ( !
    $weeks && !$days && !$hours && !$mins && !$sec )
        {
            
    $str .= '0 seconds ago';
        }
        else
        {
            
    $str .= ' ago';
        }
       
        return 
    $str;
    }
    ?>


  •  

    Posting Permissions

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