Re: timestamp

From: Date: Fri, 22 Aug 2003 19:03:43 +0000
Subject: Re: timestamp
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-160438@lists.php.net to get a copy of this message
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.

« previous php.general (#160438) next »