Re: newbie - problems with Select and timestamp(14) calculation
| From: | Jyrki Leppala | Date: | Thu, 18 Oct 2001 17:21:14 +0000 |
| Subject: | Re: newbie - problems with Select and timestamp(14) calculation | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-13496@lists.php.net to get a copy of this message | ||
Hi,
There seems to be several ways to compare time. This is what I use
to log out visitors if they do nothing in 1000 seconds. This would be
easier to do with sessions, but when I made the site my ISP did not
have PHP 4.x available. logtime column type is DATETIME, and it
stores the date as mm-dd-yyyy. UNIX_TIMESTAMP is seconds
from some date in 1970(?), but you have to be prepared for the
overflow problem in 2037.
I have no idea about the performance issues of this setup, but it
works fine for me.
Regards,
Jyrki Leppala
$sql = "SELECT (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(logtime)) AS timediff
FROM yourtable WHERE sessionid='$sessionid' ";
$result = mysql_query( $sql ) or die ( 'Ei voi lukea' );
$row = mysql_fetch_array($result);
if ($row[timediff]>1000) $userlevel=0; // or whatever you need to do here
$sql = "UPDATE table SET logtime=SYSDATE(),
userlevel='$userlevel' WHERE sessionid='$sessionid' ";
$result = mysql_query( $sql ) or die ( 'Ei voi päivittää' );
On 18 Oct 01, at 16:11, p.whiter wrote:
From: "p.whiter" <p.whiter@0800dial.com>
To: <php-db@lists.php.net>
Date sent: Thu, 18 Oct 2001 16:11:23 +0100
Subject: Re: [PHP-DB] newbie - problems with Select and timestamp(14) calculation
> Thanks for the reply, but the Timestamp(14) column (log_time) in my DB
> saves the time as '20011018134612' this is the same format as the
> NOW()+0 I think?
>
> I have tried various methods to get this to work. I've gone through
> the manual and various books I have here but am having no joy at all.
>
> I have spent far too much time on this, it really should be quite
> straightforward to compare against a Timestamp column!! If anyone else
> has any ideas......
>
> Thanks
> Paul
>