Web Hosting Talk







View Full Version : PHP: subtracting mktime() timestamps


shi_bmz
07-28-2003, 10:59 PM
I'm having trouble with the following code:

// first time through the page:
$start_time = mktime();
session_register('start_time');
...
// second time through:
$T01 = mktime() - $start_time;
session_register('T01');
...
// third time through:
$T02 = mktime() - $T01;
session_register('T02');
...

when I subtract $start_time from each consecutive $T0x timestamp I get the expected result.

However when I subtract $T01 from $T02 etc, every other result is a very large number, as if it came out negative and is being represented as an unsigned int.

Can anyone suggest what's going on?

thanks,
Shi.

dreamrae.com
07-29-2003, 08:13 PM
are you sure you are not supposed to be using just time() instend of mktime()

shi_bmz
07-29-2003, 10:57 PM
thanks for the reply - the PHP book I read used mktime() so that's why I used that - when I tried changing the code to use time() I got the same result - any other ideas?

shi_bmz
07-30-2003, 12:34 AM
just figured it out - D'OH!

$T02 = time() - $start_time - $T01;

(only $start_time is a full timestamp, all the others are just small elapsed times)