Ciao gente, ho una funzione che mi mette a video il tempo impiegato ad eseguire una determinata operazione.
Ho sempre pensato andasse bene, oggi mi han detto che ha dato alcuni risultati assurdi, ma non mi pare presenti problemi...
Riuscite a darci un occhio??
Ho un DB con l'orario di inizio e di fine dell'operazione, questa la dichiarazione:
Codice PHP:
CREATE TABLE `tabella` (
`id_ug` int(10) NOT NULL auto_increment,
`id_u` int(10) NOT NULL default '0',
`id_g` int(10) NOT NULL default '0',
`active` int(1) NOT NULL default '0',
`start` timestamp NOT NULL default CURRENT_TIMESTAMP,
`end` timestamp NOT NULL default '0000-00-00 00:00:00',
`score` int(5) NOT NULL default '0',
PRIMARY KEY (`id_ug`)
)
con start ed end i miei valori.
Ho poi la funzione che legge i valori dal DB e li passa a questa funzione:
Codice PHP:
function get_date_diff($startTime, $endTime){
$datestartTime = date_create($startTime);
$dateendTime = date_create($endTime);
$timestampstart = strtotime($datestartTime->format("Y-m-d H:i:s"));
$timestampend = strtotime($dateendTime->format("Y-m-d H:i:s"));
## difference between the two in seconds
$time_period = ( $timestampend - $timestampstart );
$days = 0;
$hours = 0;
$minutes = 0;
$seconds = 0;
$time_increments = array( 'g' => 86400,
'h' => 3600,
'm' => 60,
's' => 1 );
## will hold our values for ( day, minute, hour, seconds )
$time_span = array();
## cycle through time_increments
while( list( $key, $value ) = each( $time_increments )) {
$this_value = (int) ( $time_period / $value );
$time_period = ( $time_period % $value );
# save value
$time_span[$key] = $this_value;
}
$result = "";
## show results
while( list( $key, $value ) = each( $time_span )) {
if($value != 0){
$result .= "$value$key ";
}
}
return $result;
}
E poi faccio una echo get_data_diff(valore_start, valore_end);
vedete qualche caso strano in cui potrebbe non funzionare?? :master:
Grazie mille!
TeO