GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Help With PHP and timestamp (https://gfy.com/showthread.php?t=436141)

Dusen 02-23-2005 10:09 PM

Help With PHP and timestamp
 
I set this up:

$time1=time();

Later On,

$time2=time();

if I:

echo $time1 -> 1109145600
echo $time2 -> 1109201240

But if I

echo($time2 - $time1) -> -1109145600

Why? Why is it not 55640?

Can Anyone help?

azguy 02-23-2005 10:16 PM

Can't be.

But try echo((int)$time2 - (int)$time1);

MikeXAMO 02-23-2005 10:30 PM

you sure your echo statement is exactly as shown? It should print 55640, unless you misspelled your variable, or maybe forgot to put brackets around your math statement.

Try doing:

Code:

$time1=time();
$time2=time();
$result=$time2-$time1;
echo $result;

That should guarantee you the result you want. You shouldn't have to use typecasting (int) if you assigned your variables using the time() function, it will return an integer.

richard 02-23-2005 10:30 PM

My guess is that you've made a type on the echo?

ie PHP is calculating "0-$time1"

MikeXAMO 02-23-2005 10:30 PM

by the way, if you are timing your application, use microtime() as it is more precise (milliseconds).

Dusen 02-23-2005 10:42 PM

Damn, I should be in bed. That's exactly what it was doing.

0-$time1

mistyped var.

Thanks for the help guys.

azguy 02-23-2005 10:44 PM

hehe :) :)


All times are GMT -7. The time now is 04:58 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123