Re: select based on time/date

From: Date: Wed, 26 Sep 2001 13:37:50 +0000
Subject: Re: select based on time/date
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-68851@lists.php.net to get a copy of this message
The reason my query didn't work is you have time_in as a varchar. Change it to a datetime field or timestamp field and it should work. I would suggest making it a timestamp field. That way whenever you update the row (probably update the session field with a new session) MySQL will automatically set time_in to Now(). This will avoid a lot of headache for you =) Sheridan Saint-Michel Website Administrator FoxJet, an ITW Company www.foxjet.com ----- Original Message ----- From: "Jason Dulberg" <jdulberg@nas.net> To: "Sheridan Saint-Michel" <webmaster@foxjet.com>; <php-general@lists.php.net> Sent: Tuesday, September 25, 2001 5:08 PM Subject: RE: [PHP] select based on time/date > I tried basically what you have but I got an error: > > $sql="select * from logged_in where time_in + interval 1 hour <= now()"; > $result = mysql_query($sql); > > If it will help, here's the table structure -- looks like my structure is > bit different from what I orignally posted: > > CREATE TABLE logged_in ( > id tinyint(4) DEFAULT '0' NOT NULL auto_increment, > session varchar(100) DEFAULT '0' NOT NULL, > time_in varchar(50) NOT NULL, > KEY id (id) > ); > > Thanks again. > > __________________ > Jason Dulberg > Extreme MTB > http://extreme.nas.net > > > > The problem with this is curtime returns a number in HHMMSS > > format and your > > extract > > returns MM so you get HHMMSS - MM which is always going to be greater than > > 60 > > unless you are running your script in the first minute of the day (ie > > 000037 - 49). > > > > Try this instead: > > > > select * from sessions where $timein + interval 1 hour <= now(); > > ----- Original Message ----- > From: "Jason Dulberg" <jdulberg@nas.net> > To: <huntsman@www.nisu.flinders.edu.au>; <php-general@lists.php.net> > Sent: Tuesday, September 25, 2001 2:35 PM > Subject: RE: [PHP] select based on time/date > > > > I had a look at the DATE_FORMAT info on the mysql doc page and its a bit > > > easier to understand than the CONCATS. > > > > > > Would I want to use the CURTIME() function since I would want to select > > > sessions based on the hour? How would I go about combining CURTIME with > > the > > > rest of my query? > > > > > > Theoretically, here is what I understand, please let me know whether or > > not > > > I am correct: > > > > > > select * from sessions where (CURTIME() - EXTRACT(MINUTE FROM > > $timein) >= > > > 60); > > > //where 60 is the lifespan of the session

« previous php.general (#68851) next »