www.webdeveloper.com
Results 1 to 4 of 4

Thread: Want to convert DateTime difference result to Minutes

Threaded View

  1. #1
    Join Date
    Dec 2008
    Posts
    10

    Want to convert DateTime difference result to Minutes

    Hi Friends,

    I'm struck up in converting the DateTime difference result as Minutes, could you please anyone help me on this?

    Here am explaining my trouble:
    I'm fetching start and end time from MySQL (saved in the form of datetime type; e.g $start = '2010-10-22 11:15:09'; $end = '2010-10-23 19:08:16'
    using the below function I got the difference perfectly!
    like : Array ( [days] => 1 [hours] => 7 [minutes] => 53 [seconds] => 7 )

    I want to have the complete datetime difference in the form of minutes?
    <?php
    function get_time_difference( $start, $end ){
    $uts['start'] = strtotime( $start );
    $uts['end'] = strtotime( $end );
    if( $uts['start']!==-1 && $uts['end']!==-1 )
    {
    if( $uts['end'] >= $uts['start'] )
    {
    $diff = $uts['end'] - $uts['start'];
    if( $days=intval((floor($diff/86400))) )
    $diff = $diff &#37; 86400;
    if( $hours=intval((floor($diff/3600))) )
    $diff = $diff % 3600;
    if( $minutes=intval((floor($diff/60))) )
    $diff = $diff % 60;
    $diff = intval( $diff );
    return( array('days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff) );
    }
    else
    {
    trigger_error( "Ending date/time is earlier than the start date/time", E_USER_WARNING );
    }
    }
    else
    {
    trigger_error( "Invalid date/time data detected", E_USER_WARNING );
    }
    return( false );
    }


    $start = '2010-10-22 11:15:09';
    $end = '2010-10-23 19:08:16';

    $diff = get_time_difference($start,$end);
    print_r ($diff);
    // echo http_build_query($diff);
    ?>
    Regards,
    Thirilog
    Last edited by Thirilog; 10-25-2010 at 06:54 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles