Autor Zpráva
Anonymní
Profil *
mám dvě data jedno je třeba 2007-08-19 00:01:00 a 2007-08-18 21:17:20. potřebuju zjisti jaký je rozdíl v hodinách mezi prvním a druhým datem. Pokoším se na to přijít, ale nějak se mi nedaří... díky...
x
Profil *
*a druhé je 2007-08-18 21:17:20.
tiso
Profil
preveď si ich na timestamp pomocou funkcie strtotime() a potom ich od seba odpočítaj... pokiaľ chceš rozdiel v hodinách tak to podeľ 3600 a máš výsledok...
Anonymní
Profil *
už jsem to vyřešíl touhle docela užitečnou fcí:

/**
* Function to calculate date or time difference.
*
* Function to calculate date or time difference. Returns an array or
* false on error.
*
* @author J de Silva <giddomains@gmail.com>
* @copyright Copyright &copy; 2005, J de Silva
* @link http://www.gidnetwork.com/b-16.html Get the date / time difference with PHP
* @param string $start
* @param string $end
* @return array ['days', 'hours', 'minutes', 'seconds']
*/
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 );
}

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0