Re: MySQL query

From: Date: Mon, 12 Jan 2004 21:00:14 +0000
Subject: Re: MySQL query
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-174372@lists.php.net to get a copy of this message
From: "Ashley M. Kirchner" <ashley@pcraft.com> > >RD> SELECT whatever FROM table WHERE date_column_name BETWEEN '2004-01-09 > >RD> 00:00:00' AND '2004-01-04 23:59:59' > > > >Actually sorry, inverse the seconds (put the 00:00:00 onto the lower > >date, the 4th) so it encompasses the whole period. You might actually > >be able to not even include the seconds, try it and see what happens. > > > > > Assume I don't know what those dates are. I need to search based on > whatever the current date is, and search between 2 and 7 days back. The > dates in my previous post were simply an example. Should have said that in the first place. :) SELECT * FROM table WHERE TO_DAYS(datetimefield) BETWEEN TO_DAYS(CURDATE() - INTERVAL 2 DAY) AND TO_DAYS(CURDATE()) The "2" in the query can be a PHP variable ranging from 2 - 7, if you want. ---John Holmes...

« previous php.general (#174372) next »