Autor | Zpráva | ||
---|---|---|---|
Anonymní Profil * |
#1 · Zasláno: 19. 8. 2007, 01:30:32
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 * |
#2 · Zasláno: 19. 8. 2007, 01:31:34
*a druhé je 2007-08-18 21:17:20.
|
||
tiso Profil |
#3 · Zasláno: 19. 8. 2007, 02:12:20
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 * |
#4 · Zasláno: 19. 8. 2007, 02:24:45
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 © 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 ); } |
||
Časová prodleva: 17 let
|
0