Jump to content

mysql timestamp manipulation


Vivid Lust

Recommended Posts

good solution found here: http://www.phpbuilder.com/board/showthread.php?t=10100466

 

## example start/end dates
$startdate = ( time() - 3587 );
$enddate = time();

## difference between the two in seconds
$time_period = ( $enddate - $startdate );

$days = 0;
$hours = 0;
$minutes = 0;
$seconds = 0;

$time_increments = array( 'Days' => 86400,
'Hours' => 3600,
'Minutes' => 60,
'Seconds' => 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;
}


## show results
while( list( $key, $value ) = each( $time_span )) {
print "$key $value<br>\n";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.