On Fri, 2003-08-22 at 11:50, John Taylor-Johnston wrote:
> I'm creating a counter.
> 
> I want a timestamp where I can calculate if a time stamp is older than one hour, if 
> so do X, if not do Y.

so, you have the timestamp already correct?  in your mysql db.  all you
should need to do is get the unix timestamp from that field: 

SELECT UNIX_TIMESTAMP(whateveryourtimestampfieldiscalled) from mytable
where foo;

and compare it to the current time from php:

$timeStampTime = value you got from DB;
$currentTime = time();

these are just integers, so you can easily look to see if the timestamp
is over an hour old.  A unix timestamp is simply the number of seconds
that have elapsed since the beginning of the unix epoch, so if you know
how many seconds there are in an hour, you can determine if the
$timeStampTime is over an hour old.

something like: 

if $timeStampTime + 3600 < $currentTime { 
  echo "I'm over an hour old"; 
} else {
  echo "I'm not an hour old";
}

should work. 

hth,
gabe.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to