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?
[QUOTE]
<?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 % 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