Sir, I have these codes

function date_getFullTimeDifference( $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( $years=intval((floor($diff/31104000))) )
$diff = $diff % 31104000;
if( $months=intval((floor($diff/2592000))) )
$diff = $diff % 2592000;
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 );
$abc=(array('years'=>str_pad($years,2,0,0),'months'=>str_pad($months,2,0,0),'days'=>str_pad($days,2,0,0), 'hours'=>str_pad($hours,2,0,0), 'minutes'=>str_pad($minutes,2,0,0), 'seconds'=>str_pad($diff,2,0,0)) );
return($abc);
}
else
{
echo "Ending date/time is earlier than the start date/time";
}
}
else
{
echo "Invalid date/time data detected";
}
}
echo '<pre>';
print_r(date_getFullTimeDifference('2016-02-09 15:24:11.000','2017-02-07 15:34:11.000'));

The above code displays this result
Array
(
[years] => 01
[months] => 00
[days] => 04
[hours] => 00
[minutes] => 10
[seconds] => 00
)
But I want to save result in variable $var_restult like this
$var_restult=01-00-04,00:10:00
Please help

Recommended Answers

All 3 Replies

I would suggest you to make use of strtotime() for both dates and then substract the start timestamp from the end timestamp.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.